Skip to content

Instantly share code, notes, and snippets.

@astockwell
Created June 1, 2013 00:15
Show Gist options
  • Save astockwell/5688782 to your computer and use it in GitHub Desktop.
Save astockwell/5688782 to your computer and use it in GitHub Desktop.
Simple JS timing/performance/latency testing script (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() {
function_to_run_that_takes_time();
});
$('#output').text(elapsed + 'ms');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment