-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathaddBenchmarkEntry.ts
More file actions
41 lines (36 loc) · 1.46 KB
/
addBenchmarkEntry.ts
File metadata and controls
41 lines (36 loc) · 1.46 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
import { Benchmark } from './extract';
import * as core from '@actions/core';
import { BenchmarkSuites } from './write';
import { normalizeBenchmark } from './normalizeBenchmark';
export function addBenchmarkEntry(
benchName: string,
benchEntry: Benchmark,
entries: BenchmarkSuites,
maxItems: number | null,
): { prevBench: Benchmark | null; normalizedCurrentBench: Benchmark } {
let prevBench: Benchmark | null = null;
let normalizedCurrentBench: Benchmark = benchEntry;
// Add benchmark result
if (entries[benchName] === undefined) {
entries[benchName] = [benchEntry];
core.debug(`No suite was found for benchmark '${benchName}' in existing data. Created`);
} else {
const suites = entries[benchName];
// Get the last suite which has different commit ID for alert comment
for (const e of [...suites].reverse()) {
if (e.commit.id !== benchEntry.commit.id) {
prevBench = e;
break;
}
}
normalizedCurrentBench = normalizeBenchmark(prevBench, benchEntry);
suites.push(normalizedCurrentBench);
if (maxItems !== null && suites.length > maxItems) {
suites.splice(0, suites.length - maxItems);
core.debug(
`Number of data items for '${benchName}' was truncated to ${maxItems} due to max-items-in-charts`,
);
}
}
return { prevBench, normalizedCurrentBench };
}