Skip to content

Instantly share code, notes, and snippets.

@emalgholzad
Created June 7, 2018 15:48
Show Gist options
  • Save emalgholzad/a91a8aff177cc28a5f7e14fade9426b1 to your computer and use it in GitHub Desktop.
Save emalgholzad/a91a8aff177cc28a5f7e14fade9426b1 to your computer and use it in GitHub Desktop.
Debug for profiling and logging
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