Created
October 12, 2016 01:01
-
-
Save trafficinc/ce020482d46453a87e21067d5d398973 to your computer and use it in GitHub Desktop.
Mini Profile, a super simple JavaScript profiling module
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
// Small Profiling Lib | |
// - How to do use | |
// Profile.start('functionName'); | |
// function functionName(); // function you want to profile | |
// Profile.end(); | |
// | |
var Profile = (function () { | |
var t1; | |
var t0; | |
var fname; | |
var start = function(name) { | |
if (name == undefined || name == null) { | |
fname = ''; | |
} else { | |
fname = name; | |
} | |
t0 = performance.now(); | |
}; | |
var end = function() { | |
t1 = performance.now(); | |
show(); | |
}; | |
var show = function () { | |
var result = (t1 - t0); | |
console.debug('%cCall to [%s] took %d milliseconds', 'color: blue;', fname, result); | |
}; | |
return { | |
start: start, | |
end: end | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment