Skip to content

Instantly share code, notes, and snippets.

@trafficinc
Created October 12, 2016 01:01
Show Gist options
  • Save trafficinc/ce020482d46453a87e21067d5d398973 to your computer and use it in GitHub Desktop.
Save trafficinc/ce020482d46453a87e21067d5d398973 to your computer and use it in GitHub Desktop.
Mini Profile, a super simple JavaScript profiling module
// 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