Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created March 28, 2011 15:26
Show Gist options
  • Save benfoxall/890653 to your computer and use it in GitHub Desktop.
Save benfoxall/890653 to your computer and use it in GitHub Desktop.
/*
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