Skip to content

Instantly share code, notes, and snippets.

@jbgo
Created March 8, 2011 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbgo/860669 to your computer and use it in GitHub Desktop.
Save jbgo/860669 to your computer and use it in GitHub Desktop.
quick and dirty way to check performance of a javascript function in the console
function time(func, repeats) {
var t0 = Date.now(), t1 = null;
for (var i = 0; i < repeats; ++i) {
func();
}
t1 = Date.now();
return t1 - t0;
}
// example
console.info(time(function() {
'1,2,3,4,5'.split(',').join('.');
}, 10000) + 'ms');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment