( base: BenchmarkRunResult, head: BenchmarkRunResult, )
| 180 | |
| 181 | /** Compare two benchmark snapshots and mark only material regressions as failures. */ |
| 182 | export function compareBenchmarkRuns( |
| 183 | base: BenchmarkRunResult, |
| 184 | head: BenchmarkRunResult, |
| 185 | ): BenchmarkComparisonResult { |
| 186 | const baseByName = new Map(base.results.map((result) => [result.name, result])); |
| 187 | const headByName = new Map(head.results.map((result) => [result.name, result])); |
| 188 | const acceptedRegressionNames = new Set( |
| 189 | (head.acceptedRegressions ?? []).map((entry) => entry.name), |
| 190 | ); |
| 191 | const names = [...new Set([...baseByName.keys(), ...headByName.keys()])].sort(); |
| 192 | const rows: BenchmarkComparisonRow[] = names.map((name) => { |
| 193 | const baseResult = baseByName.get(name); |
| 194 | const headResult = headByName.get(name); |
| 195 | const resultForMetadata = headResult ?? baseResult; |
| 196 | const threshold = comparableThreshold(baseResult, headResult); |
| 197 | |
| 198 | if (!baseResult && headResult) { |
| 199 | return { |
| 200 | name, |
| 201 | unit: headResult.unit, |
| 202 | baseMedian: 0, |
| 203 | headMedian: headResult.median, |
| 204 | absoluteDelta: headResult.median, |
| 205 | relativeDelta: Number.POSITIVE_INFINITY, |
| 206 | threshold, |
| 207 | status: headResult.comparable ? "missing-base" : "informational", |
| 208 | source: headResult.source, |
| 209 | }; |
| 210 | } |
| 211 | |
| 212 | if (baseResult && !headResult) { |
| 213 | return { |
| 214 | name, |
| 215 | unit: baseResult.unit, |
| 216 | baseMedian: baseResult.median, |
| 217 | headMedian: 0, |
| 218 | absoluteDelta: -baseResult.median, |
| 219 | relativeDelta: -1, |
| 220 | threshold, |
| 221 | status: baseResult.comparable ? "missing-head" : "informational", |
| 222 | source: baseResult.source, |
| 223 | }; |
| 224 | } |
| 225 | |
| 226 | const checkedBase = baseResult!; |
| 227 | const checkedHead = headResult!; |
| 228 | const absoluteDelta = checkedHead.median - checkedBase.median; |
| 229 | const row: BenchmarkComparisonRow = { |
| 230 | name, |
| 231 | unit: checkedHead.unit, |
| 232 | baseMedian: checkedBase.median, |
| 233 | headMedian: checkedHead.median, |
| 234 | absoluteDelta, |
| 235 | relativeDelta: relativeDelta(checkedBase.median, checkedHead.median), |
| 236 | threshold, |
| 237 | status: "informational", |
| 238 | source: resultForMetadata!.source, |
| 239 | }; |
no test coverage detected