Created
June 7, 2018 15:48
-
-
Save emalgholzad/a91a8aff177cc28a5f7e14fade9426b1 to your computer and use it in GitHub Desktop.
Debug for profiling and logging
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
var debug = debug || {}; | |
debug = { | |
on : false, | |
startTime: 0, | |
partialTime: 0, | |
// start the profiling | |
start : function(){ | |
debug.on = true; | |
startTime = Date.now(); | |
partialTime = Date.now(); | |
log("======= DEBUG START ========="); | |
}, | |
// log with current time elapsed from start | |
log : function(message){ | |
if (!debug.on) { | |
return; | |
} else { | |
log("==" + (Date.now() - startTime) + "ms== " + message); | |
} | |
}, | |
// log with partial time elapsed and resets partial time | |
logPart : function(message){ | |
if (!debug.on) { | |
return; | |
} else { | |
log("--" +(Date.now() - partialTime) + "ms-- " + message); | |
partialTime = Date.now(); | |
} | |
}, | |
// end debug, log total time | |
end : function(){ | |
if (!debug.on) { | |
return; | |
} else { | |
log("======= DEBUG END: " + (Date.now() - startTime) + "ms ========="); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment