I've started using performance
API in javascript to analyze the execution time of functions. The code is given below:
var iniT,finT;
iniT = performance.now();
functionCall();
finT = performance.now();
console.log(finT-iniT);
When I run this code multiple times, each time I get different outputs even though the code and the values involved are the same. Sometimes the difference is as much as +80%. (I am talking about milliseconds, but still...).
Sample o/p:
6.053819752878553
9.16106501362151
5.987994283801299
Is there anyway to make these outputs to have a lesser variance from each other? Not just asking about the code above, but are there any better alternative profiler? Is there anything I could do to the development environment (I am using the latest Chrome, not many extensions)?
(For instance, would iterating this in a loop and taking the average be better way to go?)