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