Skip to content

Instantly share code, notes, and snippets.

@michaeldwan
Created March 18, 2011 20:51
Show Gist options
  • Save michaeldwan/876813 to your computer and use it in GitHub Desktop.
Save michaeldwan/876813 to your computer and use it in GitHub Desktop.
Simple Javascript function profiling
// 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