-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathserializeBenchmark.ts
58 lines (54 loc) · 965 Bytes
/
serializeBenchmark.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
55
56
57
58
import { Task } from "tinybench";
export type Benchmark = {
name: string;
date: string;
totalTime: number;
min: number;
max: number;
samples: number;
period: number;
mean: number;
variance: number;
sd: number;
sem: number;
moe: number;
rme: number;
};
export function serializeBenchmark(tasks: Task[]): Benchmark[] {
return tasks.map(({ name, result }) => {
if (!result) {
throw new Error(`Task ${name} has no result`);
}
if (result.error) {
throw new Error(`Task ${name} has an error: ${result.error}`);
}
const {
totalTime,
min,
max,
samples,
period,
mean,
variance,
sd,
sem,
moe,
rme
} = result;
return {
name,
date: new Date().toISOString(),
totalTime,
min,
max,
samples: samples.length,
period,
mean,
variance,
sd,
sem,
moe,
rme
};
});
}