JavaScript Benchmark Runner
Times a snippet over many iterations and says when the result is too small to believe.
Loading the tool…
How to use this tool
- Paste the code you want timed. It becomes the body of a function that is called repeatedly.
- Return or accumulate the result so the engine cannot optimise the work away.
- Set the iteration count high enough that the total run takes a few hundred milliseconds.
- 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.