Skip to content

Commit a1527d5

Browse files
--wip-- [skip ci]
1 parent fc28669 commit a1527d5

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

packages/vitest-plugin/benches/timing.bench.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ describe("timing tests", () => {
99
await sleep(1);
1010
});
1111

12-
bench("wait 500ms", async () => {
13-
await sleep(500);
14-
});
15-
16-
bench("wait 1sec", async () => {
17-
await sleep(1_000);
18-
});
12+
// bench("wait 500ms", async () => {
13+
// await sleep(500);
14+
// });
15+
//
16+
// bench("wait 1sec", async () => {
17+
// await sleep(1_000);
18+
// });
1919
});

packages/vitest-plugin/src/walltime.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "@codspeed/core";
77
import { BenchTaskResult, Suite, Task } from "vitest";
88
import { NodeBenchmarkRunner } from "vitest/runners";
9+
import { getBenchOptions } from "vitest/suite";
910
import { patchRootSuiteWithFullFilePath } from "./common";
1011

1112
declare const __VERSION__: string;
@@ -81,28 +82,36 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
8182
): Promise<Benchmark | null> {
8283
const uri = `${suitePath}::${task.name}`;
8384

85+
8486
const result = task.result;
8587
if (!result) {
8688
console.warn(` ⚠ No result data available for ${uri}`);
8789
return null;
8890
}
8991

9092
try {
93+
// Get tinybench configuration options from vitest
94+
const benchOptions = getBenchOptions(task as any);
95+
9196
const stats = this.convertVitestResultToBenchmarkStats(
92-
result as VitestTaskResult
97+
result as VitestTaskResult,
98+
benchOptions
9399
);
94100

95101
if (stats === null) {
96102
console.log(` ✔ No walltime data to collect for ${uri}`);
97103
return null;
98104
}
99-
105+
106+
// Convert warmup time and iterations to nanoseconds
107+
const ms_to_ns = (ms: number) => ms * 1_000_000;
108+
100109
const coreBenchmark: Benchmark = {
101110
name: task.name,
102111
uri,
103112
config: {
104-
warmup_time_ns: null, // Vitest doesn't expose this in task.result
105-
min_round_time_ns: null, // Vitest doesn't expose this in task.result
113+
warmup_time_ns: benchOptions.warmupTime ? ms_to_ns(benchOptions.warmupTime) : null,
114+
min_round_time_ns: benchOptions.time ? ms_to_ns(benchOptions.time) : null,
106115
},
107116
stats,
108117
};
@@ -119,14 +128,16 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
119128
}
120129

121130
private convertVitestResultToBenchmarkStats(
122-
result: VitestTaskResult
131+
result: VitestTaskResult,
132+
benchOptions: { time?: number; warmupTime?: number; warmupIterations?: number; iterations?: number }
123133
): BenchmarkStats | null {
124134
const benchmark = result.benchmark;
125135

126136
if (!benchmark) {
127137
throw new Error("No benchmark data available in result");
128138
}
129139

140+
130141
// All tinybench times are in milliseconds, convert to nanoseconds
131142
const ms_to_ns = (ms: number) => ms * 1_000_000;
132143

@@ -164,7 +175,7 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
164175
rounds: 1, // Tinybench only runs one round
165176
iqr_outlier_rounds,
166177
stdev_outlier_rounds,
167-
warmup_iters: 0, // TODO: get warmup iters here
178+
warmup_iters: benchOptions.warmupIterations || 0,
168179
};
169180
}
170181
}

0 commit comments

Comments
 (0)