Skip to content

Instantly share code, notes, and snippets.

Created August 22, 2012 14:27
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do? polyfill
var perfNow;
var perfNowNames = ['now', 'webkitNow', 'msNow', 'mozNow'];
if(!!w['performance']) for(var i = 0; i < perfNowNames.length; ++i)
var n = perfNowNames[i];
perfNow = function(){return w['performance'][n]()};
perfNow =;
w.perfNow = perfNow;
// Usage
Copy link

Note that doesn't exist in IE8, so you may also need to add something along the lines of:

if( {
    perfNow =;
} else {
    perfNow = +(new Date());

Copy link

dsamarin commented Jun 1, 2013

+(new Date()) // this is a number
function now() { return +(new Date()); } // this is a function that returns a number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment