JavaScript

JavaScript Benchmark Runner

Times a snippet over many iterations and says when the result is too small to believe.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the code you want timed. It becomes the body of a function that is called repeatedly.
  2. Return or accumulate the result so the engine cannot optimise the work away.
  3. Set the iteration count high enough that the total run takes a few hundred milliseconds.
  4. Select Run the benchmark, and raise the iterations if the result warns that the run was too short.

What javascript benchmark runner does

Wrapping something in a pair of Date.now() calls gives a number, and the number is usually wrong. The first call to a function is compiled rather than optimised, so timing one iteration measures the compiler. Timing a hundred measures the clock. And a modern engine will delete work whose result is never used, which is how a loop of ten million operations finishes in nought milliseconds.

This page runs the snippet once before the clock starts, so the warm-up is not counted, then runs it your chosen number of times inside an isolated worker with no network access and no view of this page. You get the total, the time per iteration in whatever unit makes it readable, and an operations-per-second figure. If the whole run finished too quickly to be measured reliably it says so and tells you to raise the iteration count, rather than reporting a precise-looking number built on clock noise.

Frequently asked questions

Because the whole run finished in less time than the clock available in a worker can resolve cleanly. At that scale the per-iteration figure is mostly timer noise. Raise the iteration count until the total is at least a few hundred milliseconds and the number becomes meaningful.

The engine deleted it. Work whose result is never used can be removed entirely, and modern engines do exactly that. Return the value, or accumulate it into a variable that you return, so the result is observable and the work has to happen.

No. The snippet is run once before the clock starts, so the initial compilation is not counted. What you are measuring is the optimised steady state, which is what you usually care about — though it does mean a genuinely cold first call is not what this page reports.

Run each one separately with the same iteration count and compare the operations-per-second figures. Timing both in one snippet is worse, not better: whichever runs second benefits from a warmed-up engine and looks faster than it is.