Last active
July 16, 2017 00:34
-
-
Save dzek69/5dbab26c0a70d566e7f95cbcb906cdf1 to your computer and use it in GitHub Desktop.
measure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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