Skip to content

Instantly share code, notes, and snippets.

@curlup
Forked from pmeenan/user-timing-rum.js
Last active August 29, 2015 14:20
Show Gist options
  • Save curlup/f760bee40b7b51ba9f24 to your computer and use it in GitHub Desktop.
Save curlup/f760bee40b7b51ba9f24 to your computer and use it in GitHub Desktop.
;(function () {
var object = typeof window != 'undefined' ? window : exports,
marks = [];
object.performance || (object.performance = {});
object.performance.now || (
object.performance.now = performance.now || performance.webkitNow ||
performance.msNow || performance.mozNow);
if (!object.performance.now){
var start = Date.now ? Date.now() : +(new Date());
if (performance.timing && performance.timing)
start = performance.timing.navigationStart
object.performance.now = (function(){
var nowOffset = Date.now ? Date.now() : +(new Date());
return nowOffset - start;
});
}
object.performance.mark || (
object.performance.mark =
object.performance.webkitMark ? object.performance.webkitMark :
(function (label) {
marks.push({'name':label,'entryType':'mark','startTime':object.performance.now(),'duration':0});
}));
object.performance.getEntriesByType || (
object.performance.getEntriesByType =
object.performance.webkitGetEntriesByType ? object.performance.webkitGetEntriesByType :
(function (type) {
return type == 'mark' ? marks : undefined;
}));
}());
markUserTime = function(label) {
window.performance.mark(label);
if (console && console.timeStamp)
console.timeStamp(label);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment