Created
September 10, 2011 14:16
-
-
Save lsauer/1208350 to your computer and use it in GitHub Desktop.
JavaScript: Simple multi-timer for logging performance of an html page
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 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