Skip to content

Instantly share code, notes, and snippets.

@astockwell
Last active December 17, 2015 18:09
Show Gist options
  • Save astockwell/5651452 to your computer and use it in GitHub Desktop.
Save astockwell/5651452 to your computer and use it in GitHub Desktop.
Poor-man's Javascript performance timing, via http://kellegous.com/j/2013/01/26/layout-performance/
var Now;
if (typeof performance !== 'undefined' && performance.now) {
Now = function() {
return performance.now();
};
} else if (Date.now) {
Now = function() {
return Date.now();
};
} else {
Now = function() {
return new Date().getTime();
}
}
var Time = function(f) {
var s = Now();
f();
return (Now() - s) | 0;
};
// Useage
var elapsed = Time(function() {
UpdateNoThrash(data);
});
$('#example-yay-time').text(elapsed + 'ms');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment