Created
June 18, 2013 15:23
-
-
Save kislovskij/5806292 to your computer and use it in GitHub Desktop.
High resolution timer shim
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 = (function() { | |
// Returns the number of milliseconds elapsed since either the browser navigationStart event or | |
// the UNIX epoch, depending on availability. | |
// Where the browser supports 'performance' we use that as it is more accurate (microsoeconds | |
// will be returned in the fractional part) and more reliable as it does not rely on the system time. | |
// Where 'performance' is not available, we will fall back to Date().getTime(). | |
var performance = window.performance || {}; | |
performance.now = (function() { | |
return performance.now || | |
performance.webkitNow || | |
performance.msNow || | |
performance.oNow || | |
performance.mozNow || | |
function() { return new Date().getTime(); }; | |
})(); | |
return performance.now(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment