Created
March 8, 2011 18:05
-
-
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
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
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