-
-
Notifications
You must be signed in to change notification settings - Fork 515
/
Copy pathBenchmarkTest.js
51 lines (43 loc) · 1.01 KB
/
BenchmarkTest.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
import test from "ava";
import Benchmark from "../src/Benchmark/Benchmark.js";
test("Standard Benchmark", async (t) => {
await new Promise((resolve) => {
let b = new Benchmark();
b.before();
setTimeout(function () {
b.after();
t.truthy(b.getTotal() >= 0);
resolve();
}, 100);
});
});
test("Nested Benchmark (nested calls are ignored while a parent is measuring)", async (t) => {
await new Promise((resolve) => {
let b = new Benchmark();
b.before();
setTimeout(function () {
b.before();
b.after();
t.truthy(b.getTotal() <= 0.1);
b.after();
t.truthy(b.getTotal() >= 10);
resolve();
}, 100);
});
});
test("Reset Benchmark", async (t) => {
await new Promise((resolve) => {
let b = new Benchmark();
b.before();
b.reset();
setTimeout(function () {
b.before();
b.after();
t.throws(function () {
// throws because we reset
b.after();
});
resolve();
}, 100);
});
});