JavaScript Benchmark
Benchmark and compare two JavaScript functions side by side in a web worker.
Input
Output
Readme
What is a JavaScript benchmark?
A JavaScript benchmark measures how fast a piece of code executes by running it repeatedly over a fixed time period and counting how many operations per second it can complete. Benchmarking is commonly used to compare two approaches to the same problem — for example, checking whether Array.includes() is faster than Array.indexOf() for a given use case. Results can vary significantly between browsers and devices, since each JavaScript engine (V8, SpiderMonkey, JavaScriptCore) has its own optimizations and JIT compilation strategies.
Tool description
This tool lets you paste two JavaScript code snippets and run a head-to-head performance comparison directly in your browser. Each snippet is timed over a configurable duration, and the results show operations per second and average time per operation for both functions. A progress bar highlights the relative performance difference, making it easy to see which approach is faster at a glance.
Features
- Runs both snippets in a Web Worker so benchmarks never block or freeze the browser tab
- Configurable benchmark duration for balancing accuracy against wait time
- Side-by-side ops/sec comparison with a visual bar and percentage difference
How it works
Each snippet is wrapped in a loop that runs for the specified duration (default 2 seconds) after a 100 ms warmup phase to allow the JIT compiler to optimize the code. Operations are counted during the timed window, and ops/sec is calculated as count / elapsed_ms * 1000. The entire benchmark runs inside a Web Worker so it cannot access the DOM, but it has access to standard JavaScript globals like Math, Date, performance, arrays, and objects.
Tips
- Keep snippets self-contained; avoid side effects that accumulate between iterations
- Use a longer duration (3–5 seconds) for more stable results on fast operations
- Results reflect your specific browser and machine — always benchmark on the target environment