Created
March 18, 2011 20:51
-
-
Save michaeldwan/876813 to your computer and use it in GitHub Desktop.
Simple Javascript function profiling
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
// Pass a function to profile and optionally the number of times to run | |
function profile(test, times) { | |
var start = new Date().getTime(); | |
if (times === undefined) { | |
times = 100; | |
} | |
for (i = 0; i < times; ++i) { | |
test(); | |
}; | |
var end = new Date().getTime(); | |
var time = end - start; | |
print('took: ' + time); | |
} | |
// Example | |
profile(function () { | |
1 + 2; | |
}, 10000) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment