Last active
December 17, 2015 18:09
-
-
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/
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
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