Created
August 22, 2012 14:27
-
-
Save BKcore/3426111 to your computer and use it in GitHub Desktop.
Performance.now() polyfill
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
(function(w){ | |
var perfNow; | |
var perfNowNames = ['now', 'webkitNow', 'msNow', 'mozNow']; | |
if(!!w['performance']) for(var i = 0; i < perfNowNames.length; ++i) | |
{ | |
var n = perfNowNames[i]; | |
if(!!w['performance'][n]) | |
{ | |
perfNow = function(){return w['performance'][n]()}; | |
break; | |
} | |
} | |
if(!perfNow) | |
{ | |
perfNow = Date.now; | |
} | |
w.perfNow = perfNow; | |
})(window); | |
// Usage | |
console.log(window.perfNow()); |
dsamarin
commented
Jun 1, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment