1import type { Benchmark, MetricsCollection, Sampled, Standard } from "../types/benchmark.js";
2
3export class BenchmarkWrapper {
4  constructor(
5    private benchmark: Benchmark,
6    private separator: string = '_'
7  ) {
8
9  }
10
11  datasetName(): string {
12    return `${this.className()}${this.separator}${this.benchmark.name}`;
13  }
14
15  metric(label: string): Standard | undefined {
16    return this.benchmark?.metrics?.[label];
17  }
18
19  sampled(label: string): Sampled | undefined {
20    return this.benchmark?.sampledMetrics?.[label];
21  }
22
23  metricLabels(): string[] {
24    return BenchmarkWrapper.labels(this.benchmark.metrics);
25  }
26
27  sampledLabels(): string[] {
28    return BenchmarkWrapper.labels(this.benchmark.sampledMetrics);
29  }
30
31  className(): string {
32    const className = this.benchmark.className;
33    const parts = className.split('.');
34    const lastIndex = parts.length - 1;
35    return parts[lastIndex];
36  }
37
38  testName(): string {
39    return this.benchmark.name;
40  }
41
42  private static labels(collection: MetricsCollection | undefined): string[] {
43    const labels: string[] = [];
44    if (collection) {
45      for (const key in collection) {
46        if (collection.hasOwnProperty(key)) {
47          labels.push(key);
48        }
49      }
50    }
51    return labels;
52  }
53
54}
55