Optimisation - Only check browser compatability once

This saves doing the checks everytime the time functions are referenced
This commit is contained in:
griffpatch 2017-01-28 16:43:37 +00:00
parent 824628220c
commit bd405ecc4a

View file

@ -27,13 +27,12 @@ Timer.prototype.startTime = 0;
* Return the currently known absolute time, in ms precision.
* @returns {number} ms elapsed since 1 January 1970 00:00:00 UTC.
*/
Timer.prototype.time = function () {
if (Date.now) {
Timer.prototype.time = Date.now ?
function () {
return Date.now();
} else {
} : function () {
return new Date().getTime();
}
};
};
/**
* Returns a time accurate relative to other times produced by this function.
@ -42,14 +41,13 @@ Timer.prototype.time = function () {
* Not guaranteed to produce the same absolute values per-system.
* @returns {number} ms-scale accurate time relative to other relative times.
*/
Timer.prototype.relativeTime = function () {
if (typeof self !== 'undefined' &&
self.performance && 'now' in self.performance) {
return self.performance.now();
} else {
return this.time();
}
};
Timer.prototype.relativeTime =
(typeof self !== 'undefined' && self.performance && 'now' in self.performance) ?
function () {
return self.performance.now();
} : function () {
return this.time();
};
/**
* Start a timer for measuring elapsed time,