-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathbenchmarks.ts
More file actions
69 lines (63 loc) · 1.65 KB
/
benchmarks.ts
File metadata and controls
69 lines (63 loc) · 1.65 KB
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
63
64
65
66
67
68
69
import type { Bench } from 'tinybench';
import type { BenchFn, BenchmarkResult, SuiteState } from '../types/benchmarks';
export class BenchmarkSuite {
name: string;
enabled: boolean;
benchmarks: BenchFn[];
state: SuiteState;
results: BenchmarkResult[] = [];
notes?: Record<string, string>;
constructor(
name: string,
benchmarks: BenchFn[],
notes?: Record<string, string>,
) {
this.name = name;
this.enabled = false;
this.state = 'idle';
this.benchmarks = benchmarks;
this.results = [];
this.notes = notes;
}
addResult(result: BenchmarkResult) {
this.results.push(result);
}
async run() {
this.results = [];
// Run benchmarks sequentially to avoid timing interference
for (const benchFn of this.benchmarks) {
const b = await benchFn();
await b.run();
this.processResults(b);
}
this.state = 'done';
}
processResults = (b: Bench): void => {
const tasks = b.tasks;
const us = tasks.find(t => t.name === 'rnqc');
const themTasks = tasks.filter(t => t.name !== 'rnqc');
if (themTasks.length > 0) {
themTasks.map(them => {
const notes = this.notes?.[them.name] ?? '';
this.addResult({
errorMsg: undefined,
challenger: them.name,
notes,
benchName: b.name,
them: them.result,
us: us?.result,
});
});
} else if (us) {
// No comparison benchmarks, just show rnqc results
this.addResult({
errorMsg: undefined,
challenger: 'N/A',
notes: '',
benchName: b.name,
them: undefined,
us: us.result,
});
}
};
}