-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.bench.ts
54 lines (46 loc) · 1.29 KB
/
mod.bench.ts
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
import { bench, BenchmarkTimer } from "../bench.mod.ts";
import { PollingObserver } from "./mod.ts";
const runs = 3;
const iter = 1e3;
bench({
runs,
name: `runs${runs}ForPollingObserverWithSyncConditionCallbackX${iter}s`,
async func(b: BenchmarkTimer) {
let i = iter;
b.start();
while (i) {
/** NOTE(motss): Test how long it takes to instantiate, run polling, then disconnect */
const obs = new PollingObserver(() => true);
const task = new Promise(yay => (obs.onfinish = yay));
obs.observe(async () => new Promise(yay => setTimeout(yay, 1)), {
interval: 1,
timeout: 1e3
});
await task;
obs.disconnect();
i -= 1;
}
b.stop();
}
});
bench({
runs,
name: `runs${runs}ForPollingObserverWithAsyncConditionCallbackX${iter}s`,
async func(b: BenchmarkTimer) {
let i = iter;
b.start();
while (i) {
/** NOTE(motss): Test how long it takes to instantiate, run polling, then disconnect */
const obs = new PollingObserver(async () => true);
const task = new Promise(yay => (obs.onfinish = yay));
obs.observe(async () => new Promise(yay => setTimeout(yay, 1)), {
interval: 1,
timeout: 1e3
});
await task;
obs.disconnect();
i -= 1;
}
b.stop();
}
});