How to Performance Test JavaScript Code

How can I benchmark JavaScript code?

Just time several iterations of each function. One iteration probably won't be enough, but (depending on how complex your functions are) somewhere closer to 100 or even 1,000 iterations should do the job.

Firebug also has a profiler if you want to see which parts of your function are slowing it down.

Edit: To future readers, the below answer recommending JSPerf should be the correct answer. I would delete mine, but I can't because it has been selected by the OP. There is much more to benchmarking than just running many iterations, and JSPerf takes care of that for you.

Load Testing Javascript on a Webpage

Very few tools run downloaded JS code in the client/VU threads when executing a load test, for performance reasons mainly. You can try Selenium Grid or some online service based on it, like https://www.loadbooster.com/ or Blazemeter, but if you want to run tests in your own environment, Selenium Grid may be your only choice.

The alternative is to emulate the JS client side code when you script the load test scenario. Many tools can do that, at some level, but to make translation of existing JS code easier, I would choose a tool that offers a real scripting language, such as e.g. Grinder, Locust, Wrk or k6 (or possibly Gatling). k6 may be the simplest as you script it in Javascript, so translating the client-side JS code should be somewhat less work there.

  • https://k6.io
  • https://gatling.io/
  • https://locust.io
  • https://github.com/wg/wrk
  • http://grinder.sourceforge.net/


Related Topics



Leave a reply



Submit