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
How to Invoke a Jsf Managed Bean on a HTML Dom Event Using Native JavaScript
JavaScript Call() & Apply() VS Bind()
Converting an Object to a String
How to Hover in Reactjs? - Onmouseleave Not Registered During Fast Hover Over
Count Animation from Number a to B
Full Height of a HTML Element (Div) Including Border, Padding and Margin
Include a JavaScript File in Shiny App
Dynamically Load a JavaScript File
Chained Promises Not Passing on Rejection
JavaScript: Difference Between .Foreach() and .Map()
Sending Command Line Arguments to Npm Script
Force Browser to Refresh CSS, JavaScript, etc
How to Make Changeable Themes Using CSS and JavaScript
Detect CSS Transitions Using JavaScript (And Without Modernizr)