-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
59 lines (40 loc) · 1.01 KB
/
index.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var moment = require('moment');
var internals = {};
internals.now = function() {
return new Date().getTime();
};
internals.timers = {};
/**
* Start timer.
*
*/
exports.start = function(timer_name, verbose) {
if (verbose === true) {
console.log('[TIMER] start - %s', timer_name);
}
internals.timers[timer_name] = {
'start': internals.now(),
'stop': undefined,
'delta': undefined
};
return internals.timers[timer_name];
};
/**
* Stop timer and calculate delta.
*
*/
exports.stop = function(timer_name, verbose) {
var ms;
if (verbose === true) {
console.log('[TIMER] stop - %s', timer_name);
}
var timer = internals.timers[timer_name];
timer.stop = internals.now();
timer.delta = timer.stop - timer.start;
if (verbose === true) {
console.log('[TIMER] delta - %s: %s (%s seconds)', timer_name, timer.delta, timer.delta/1000);
}
ms = timer.delta;
delete internals.timers[timer_name];
return ms;
};