How can I benchmark JavaScript code? [closed]

jsperf.com is the go-to site for testing JS performance. Start there. If you need a framework for running your own tests from the command line or scripts use Benchmark.js, the library upon which jsperf.com is built.

Note: Anyone testing Javascript code should educate themselves on the pitfalls of “microbenchmarks” (small tests that target a specific feature or operation, rather than more complex tests based on real-world code patterns). Such tests can be useful but are prone to inaccuracy due to how modern JS runtimes operate. Vyacheslav Egorov’s presentation on performance and benchmarking is worth watching to get a feel for the nature of the problem(s).

Edit: Removed references to my JSLitmus work as it’s just no longer relevant or useful.

Leave a Comment