forked from svaarala/duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer-test.js
More file actions
40 lines (35 loc) · 951 Bytes
/
timer-test.js
File metadata and controls
40 lines (35 loc) · 951 Bytes
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
/*
* Test using timers and intervals.
*/
function main() {
var i;
var counters = [];
var ntimers = 0;
print('set interval timer');
var intervalTimer = setInterval(function () {
print(new Date().toISOString() + ': timers pending: ' + ntimers);
if (ntimers === 0) {
clearInterval(intervalTimer);
}
}, 500);
function addTimer(interval) {
ntimers++;
setTimeout(function () {
ntimers--;
}, interval);
}
/* Here the inserts take a lot of time because the underlying timer manager
* data structure has O(n) insertion performance.
*/
print('launch timers');
for (i = 0; i < 4000; i++) {
// Math.exp(0)...Math.exp(8) is an uneven distribution between 1...~2980.
addTimer(16000 - Math.exp(Math.random() * 8) * 5);
}
print('timers launched');
}
try {
main();
} catch (e) {
print(e.stack || e);
}