Skip to content

Instantly share code, notes, and snippets.

@phalkunz
Created June 19, 2012 02:11
Show Gist options
  • Save phalkunz/2951935 to your computer and use it in GitHub Desktop.
Save phalkunz/2951935 to your computer and use it in GitHub Desktop.
Simple JS running time profiler
/**
* Profiling (running time). For dev purpose only.
*/
(function() {
window._profiler = {
'profiles': []
};
_profiler.time = function(name) {
_profiler.profiles[name] = new Date();
};
_profiler.timeEnd = function(name) {
var diff = new Date() - _profiler.profiles[name];
print(diff);
};
var print = function (val) {
// Only print the timer when jsprofile is present in the url querystring
if(/jsprofile/.test(window.location.search)) {
alert(val);
// Self-rewrite so that from the second time it doesn't need check url string
print = function(val) {
alert(val);
}
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment