Created
March 28, 2011 15:26
-
-
Save benfoxall/890653 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
Usage: | |
t = timer(); | |
t('start') | |
…some slow script… | |
t('checkpoint'); | |
…some slow script… | |
list = t('checkpoint2'); | |
alert(list) => [start:0, checkpoint:100, checkpoint2:1302 ] | |
*/ | |
var timer = function(){ | |
var d = new Date(); | |
var start = d.getTime(); | |
var ts = []; | |
return function(mark){ | |
var d = new Date(); | |
var t = d.getTime() - start; | |
if(mark){ | |
ts.push(mark + ':' + t); | |
} else { | |
ts.push(t); | |
} | |
return ts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment