-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
64 lines (53 loc) · 1.15 KB
/
main.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
60
61
62
// function main(n) {
// let sum = 0;
// const myWorker = new Worker("worker.js");
// let counter = 0;
// for(let i = 0; i < n; i ++) {
// myWorker.postMessage(i);
// }
// myWorker.onmessage = function(e) {
// sum = sum + e.data;
// counter++;
// if (counter === n) {
// console.log(sum / n);
// }
// }
// }
// main(100);
// function main(n, counter = 0, sum = 0) {
// function testRunner() {
// window.requestAnimationFrame(() => {console.log('rerender')})
// let t0 = performance.now();
// setTimeout(() => {
// let t1 = performance.now();
// if (counter === n) {
// console.log(`${counter}: ${sum/counter}`);
// return;
// }
// sum += (t1-t0);
// counter++
// testRunner();
// }, 0)
// };
// testRunner();
// }
// main(10);
// main(1000);
function main(n, counter = 0, sum = 0) {
let myInterval;
function myTester(n) {
let t0 = performance.now();
setTimeout(() => {
let t1 = performance.now();
sum +=(t1-t0);
counter++;
if(counter === n) {
console.log(`${n}: ${sum / n}`);
clearInterval(myInterval);
}
})
}
myInterval = setInterval(myTester, 50, n);
}
main(10);
main(1000);