6
6
} from "@codspeed/core" ;
7
7
import { BenchTaskResult , Suite , Task } from "vitest" ;
8
8
import { NodeBenchmarkRunner } from "vitest/runners" ;
9
+ import { getBenchOptions } from "vitest/suite" ;
9
10
import { patchRootSuiteWithFullFilePath } from "./common" ;
10
11
11
12
declare const __VERSION__ : string ;
@@ -81,28 +82,36 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
81
82
) : Promise < Benchmark | null > {
82
83
const uri = `${ suitePath } ::${ task . name } ` ;
83
84
85
+
84
86
const result = task . result ;
85
87
if ( ! result ) {
86
88
console . warn ( ` ⚠ No result data available for ${ uri } ` ) ;
87
89
return null ;
88
90
}
89
91
90
92
try {
93
+ // Get tinybench configuration options from vitest
94
+ const benchOptions = getBenchOptions ( task as any ) ;
95
+
91
96
const stats = this . convertVitestResultToBenchmarkStats (
92
- result as VitestTaskResult
97
+ result as VitestTaskResult ,
98
+ benchOptions
93
99
) ;
94
100
95
101
if ( stats === null ) {
96
102
console . log ( ` ✔ No walltime data to collect for ${ uri } ` ) ;
97
103
return null ;
98
104
}
99
-
105
+
106
+ // Convert warmup time and iterations to nanoseconds
107
+ const ms_to_ns = ( ms : number ) => ms * 1_000_000 ;
108
+
100
109
const coreBenchmark : Benchmark = {
101
110
name : task . name ,
102
111
uri,
103
112
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 ,
106
115
} ,
107
116
stats,
108
117
} ;
@@ -119,14 +128,16 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
119
128
}
120
129
121
130
private convertVitestResultToBenchmarkStats (
122
- result : VitestTaskResult
131
+ result : VitestTaskResult ,
132
+ benchOptions : { time ?: number ; warmupTime ?: number ; warmupIterations ?: number ; iterations ?: number }
123
133
) : BenchmarkStats | null {
124
134
const benchmark = result . benchmark ;
125
135
126
136
if ( ! benchmark ) {
127
137
throw new Error ( "No benchmark data available in result" ) ;
128
138
}
129
139
140
+
130
141
// All tinybench times are in milliseconds, convert to nanoseconds
131
142
const ms_to_ns = ( ms : number ) => ms * 1_000_000 ;
132
143
@@ -164,7 +175,7 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
164
175
rounds : 1 , // Tinybench only runs one round
165
176
iqr_outlier_rounds,
166
177
stdev_outlier_rounds,
167
- warmup_iters : 0 , // TODO: get warmup iters here
178
+ warmup_iters : benchOptions . warmupIterations || 0 ,
168
179
} ;
169
180
}
170
181
}
0 commit comments