-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstopWatch.js
More file actions
97 lines (88 loc) · 2.05 KB
/
stopWatch.js
File metadata and controls
97 lines (88 loc) · 2.05 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Stopwatch class for time measurement.
*
* @author Stefan Schnell <mail@stefan-schnell.de>
* @license MIT
* @version 0.1.0
*
* Checked with Rhino engines version 1.7R4, 1.7.14 and 1.7.15
*/
var stopWatch = function() {
this.pointsInTime = [];
this._elapsedTime = 0;
this._startTime = 0;
this._stopTime = 0;
};
stopWatch.prototype = {
/**
* Delivers the elapsed time between start and stop.
*
* @function elapsedTime
* @returns {number}
*
* @example
* var oStopWatch = new stopWatch();
* oStopWatch.start();
* System.sleep(250);
* oStopWatch.stop();
* System.log(oStopWatch.elapsedTime());
*/
elapsedTime : function() {
return this._elapsedTime;
},
/**
* Sets a point in time in an array.
* This allows you to set intermediate points that can be used in
* a time measurement. They are stored in an array, so they can be
* accessed using its methods.
*
* @function pointInTime
*
* @example
* var oStopWatch = new stopWatch();
* oStopWatch.start();
* System.sleep(250);
* oStopWatch.pointInTime();
* System.sleep(250);
* oStopWatch.stop();
* oStopWatch.pointsInTime.forEach( function(pointInTime) {
* System.log(pointInTime);
* });
*/
pointInTime : function() {
this.pointsInTime.push(Date.now());
},
/**
* Starts the time measurement.
*
* @function start
*
* @example
* var oStopWatch = new stopWatch();
* oStopWatch.start();
* System.sleep(250);
* oStopWatch.stop();
* System.log(oStopWatch.elapsedTime());
*/
start : function() {
this._startTime = Date.now();
this.pointsInTime.push(this._startTime);
},
/**
* Stops the time measurement.
*
* @function stop
*
* @example
* var oStopWatch = new stopWatch();
* oStopWatch.start();
* System.sleep(250);
* oStopWatch.stop();
* System.log(oStopWatch.elapsedTime());
*/
stop : function() {
this._stopTime = Date.now();
this.pointsInTime.push(this._stopTime);
this._elapsedTime = this._stopTime - this._startTime;
}
};