Skip to content

Commit 0766b7f

Browse files
authored
feat: add median to --output-json (#5745)
1 parent b7438b9 commit 0766b7f

File tree

1 file changed

+4
-0
lines changed
  • packages/vitest/src/node/reporters/benchmark/table

1 file changed

+4
-0
lines changed

packages/vitest/src/node/reporters/benchmark/table/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ interface FormattedBenchmarkGroup {
129129
export type FormattedBenchmarkResult = Omit<BenchmarkResult, 'samples'> & {
130130
id: string
131131
sampleCount: number
132+
median: number
132133
}
133134

134135
function createFormattedBenchamrkReport(files: File[]) {
@@ -145,6 +146,9 @@ function createFormattedBenchamrkReport(files: File[]) {
145146
benchmarks.push({
146147
id: t.id,
147148
sampleCount: samples.length,
149+
median: samples.length % 2
150+
? samples[Math.floor(samples.length / 2)]
151+
: (samples[samples.length / 2] + samples[samples.length / 2 - 1]) / 2,
148152
...rest,
149153
})
150154
}

0 commit comments

Comments
 (0)