1 | import { pause } from 'myrmidon'; |
||
2 | import { BenchMark, JSONReporter } from '../entry'; |
||
3 | import { checkReportItem } from '../utils'; |
||
4 | |||
5 | suite('sequence'); |
||
6 | |||
7 | test('Positive: one iteration', async function () { |
||
8 | const bench = new BenchMark({}); |
||
9 | |||
10 | bench.sequence('before all'); |
||
11 | await pause(25); |
||
12 | bench.sequence('25ms gone'); |
||
13 | await pause(15); |
||
14 | bench.sequence('after 15ms more'); |
||
15 | await pause(50); |
||
16 | bench.sequence('end of the test'); |
||
17 | |||
18 | const report = JSON.parse(bench.report(new JSONReporter())); |
||
19 | |||
20 | checkReportItem(report, 'before all', 'benchmark', 0); |
||
21 | checkReportItem(report, '25ms gone', 'benchmark', 25); |
||
22 | checkReportItem(report, 'after 15ms more', 'benchmark', 15); |
||
23 | checkReportItem(report, 'end of the test', 'benchmark', 50); |
||
24 | }); |
||
25 | |||
26 | test('Positive: several iterations', async function () { |
||
27 | const bench = new BenchMark(); |
||
28 | |||
29 | bench.sequence('before cycle'); |
||
30 | |||
31 | for (const iter of [ 1, 2, 3 ]) { |
||
32 | const iteration = bench.iteration(iter); |
||
33 | |||
34 | iteration.sequence('before iteration'); |
||
35 | await pause(15); |
||
36 | iteration.sequence('15ms gone'); |
||
37 | await pause(10); |
||
38 | iteration.sequence('after 10ms more'); |
||
39 | await pause(20); |
||
40 | iteration.sequence('end of the iteration'); |
||
41 | } |
||
42 | |||
43 | bench.sequence('after cycle'); |
||
44 | console.log(bench.report(new JSONReporter())); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
45 | const report = JSON.parse(bench.report(new JSONReporter())); |
||
46 | |||
47 | checkReportItem(report, 'before cycle', 'benchmark', 0); |
||
48 | checkReportItem(report, 'before iteration', 'mean', 0); |
||
49 | checkReportItem(report, '15ms gone', 'mean', 15); |
||
50 | checkReportItem(report, 'after 10ms more', 'mean', 10); |
||
51 | checkReportItem(report, 'end of the iteration', 'mean', 20); |
||
52 | checkReportItem(report, 'before iteration', 'total', 3); |
||
53 | checkReportItem(report, 'after cycle', 'benchmark', 3 * (15 + 10 + 20)); |
||
54 | }); |
||
55 |