Skip to content

Instantly share code, notes, and snippets.

@saich
Created June 26, 2012 06:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saich/2993641 to your computer and use it in GitHub Desktop.
Save saich/2993641 to your computer and use it in GitHub Desktop.
window.performance.now() wrapper for profiler use
/**
* @constructor
*/
function Profiler() {
}
/**
* Uses the best resolution timer that is currently available.
* The return value of this can only be used for measuring the time interval,
* and *MUST NOT* be used to get the absolute current time.
*
* Make sure now to change any global variable/state. (Do not override the window.performance object,
* but just maintain a reference to the browser function if you just want to use it)
*
* @return {Number}
*/
Profiler.time = (function() {
var perf = window.performance || {};
var fn = perf.now || perf.mozNow || perf.webkitNow || perf.msNow || perf.oNow;
// fn.bind will be available in all the browsers that support the advanced window.performance... ;-)
return fn ? fn.bind(perf) : function() { return new Date().getTime(); };
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment