DaveGoosem
11/12/2013 - 2:55 PM

Simple Javascript Performance Testing. Write the same code using different methods and then use this to test execution time (can output it t

Simple Javascript Performance Testing. Write the same code using different methods and then use this to test execution time (can output it to console). Dev tools may / may not give you same results.

/*
* We need to run the code sample more than once to get a better idea of running time during analysis.
* set this value to be however many times you want to run the code to get a good analysis 
* of running time 
*/
var maxCount = 20;
var start = new Date().getTime();
for (var n = 0; n < maxCount; n++) {
  /* perform operation you want to measure */
}

var elapsed = new Date().getTime() - start;
console.log("code snippet ran in: " + elapsed);