-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.js
41 lines (32 loc) · 946 Bytes
/
clock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(function IIFE ( Clock ) {
window.Clock = new Clock()
})(function Clock () {
var tStart = 0
Clock.prototype.now = performance.now.bind( performance )
Clock.prototype.start = function () {
tStart = this.now()
}
Clock.prototype.restart = this.start;
Clock.prototype.get = function () {
return this.now() - tStart
}
Clock.prototype.getMilliseconds = function ( precision ) {
precision = typeof precision === "number" ? precision : 0 //isInteger... kinda...
return this.get().toFixed( precision )
}
Clock.prototype.time = function ( Name, fn ) {
console.log( Name + " starting..." )
this.start();
fn();
var tEnd = this.getMilliseconds( 2 );
console.log( Name + " ended. " + tEnd + "ms" );
return tEnd;
}
Clock.prototype.timeRaw = function ( Name, fn ) {
console.log( Name + " starting..." )
this.start();
fn();
var tEnd = this.get();
console.log( Name + " ended. " + tEnd + "ms" );
}
})