timer
by Darby Rathbone
JavaScript
var Timer = function () {
this.Start = 0;
this.End = 0;
};
Timer.prototype.grabTime = function () {
return new performance;
};
Timer.prototype.start = window.performance.now ? (performance.now() + performance.timing.navigationStart) : Date.now(); console.log(this.Start);
};
Timer.prototype.stop = function () {
setTimeout(this.End = Timer.prototype.grabTime(), 0);
/*console.log(this.Start);*/
};
Object.defineProperty(Timer.prototype, "time", {
get: function () {
console.log(this);
return this.End - this.Start;
},
configurable: false
});
var t = new Timer();
var count = 10000;
var a = [],
i = 0;
t.start();
for (; i < count; i++) {
a[i] = i;
}
t.stop();
document.body.innerHTML += t.time;