Skip to content

Instantly share code, notes, and snippets.

@dzek69
Last active July 16, 2017 00:34
Show Gist options
  • Save dzek69/5dbab26c0a70d566e7f95cbcb906cdf1 to your computer and use it in GitHub Desktop.
Save dzek69/5dbab26c0a70d566e7f95cbcb906cdf1 to your computer and use it in GitHub Desktop.
measure
var measure = function(fn, iterations, timeout) {
iterations || (iterations = 10000);
timeout || (timeout = 5000);
var i, end, total;
var timeoutMsg = "";
var start = performance.now();
for (i = 0; i < iterations; i++) {
fn();
end = performance.now();
total = end - start;
if (total > timeout) {
timeoutMsg = "[TIMEOUT] ";
break;
}
}
return timeoutMsg + "Iterations: " + i + ", Avg time: " + total/i + ", Total time: " + total;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment