Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created September 10, 2011 14:16
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 lsauer/1208350 to your computer and use it in GitHub Desktop.
Save lsauer/1208350 to your computer and use it in GitHub Desktop.
JavaScript: Simple multi-timer for logging performance of an html page
function j2timer(e){
window.tdiff || (window.tdiff = []);
window.tdlog || (window.tdlog = []);
window.fnred || (window.fnred = function(a,b){return a-b;});
//toogle statement
if( (tdiff.length+1) % 2){
tdiff.push( Date.now());
return;
}
tdlog.push(["TIMER:", Date.now()-tdiff[tdiff.length-1], "[msec]; NOW:", Date.now(), "; WHO:", e, this.constructor.toString().split("(")[0]]);
//commet this line out
//console.log(tdlog.pop().join(" ") );
}
j2timer();
...
j2timer();
This will result in:
in "dbg"- mode
426TIMER: 12 [msec]; NOW: 1315664066896 ; WHO: function DOMWindow
tdlog
[
Array[7]
0: "TIMER:"
1: 20
2: "[msec]; NOW:"
3: 1315664090219
4: "; WHO:"
5: undefined
6: "function DOMWindow"
length: 7
__proto__: Array[0]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment