|
| 1 | +import {BenchmarkFilter, CompareResponse, StatComparison} from "../types"; |
| 2 | +import {calculateComparison, TestCaseComparison} from "../data"; |
| 3 | + |
| 4 | +export type CompileBenchmarkFilter = { |
| 5 | + profile: { |
| 6 | + check: boolean; |
| 7 | + debug: boolean; |
| 8 | + opt: boolean; |
| 9 | + doc: boolean; |
| 10 | + }; |
| 11 | + scenario: { |
| 12 | + full: boolean; |
| 13 | + incrFull: boolean; |
| 14 | + incrUnchanged: boolean; |
| 15 | + incrPatched: boolean; |
| 16 | + }; |
| 17 | + category: { |
| 18 | + primary: boolean; |
| 19 | + secondary: boolean; |
| 20 | + }; |
| 21 | +} & BenchmarkFilter; |
| 22 | +export const defaultCompileFilter: CompileBenchmarkFilter = { |
| 23 | + name: null, |
| 24 | + nonRelevant: false, |
| 25 | + showRawData: false, |
| 26 | + profile: { |
| 27 | + check: true, |
| 28 | + debug: true, |
| 29 | + opt: true, |
| 30 | + doc: true, |
| 31 | + }, |
| 32 | + scenario: { |
| 33 | + full: true, |
| 34 | + incrFull: true, |
| 35 | + incrUnchanged: true, |
| 36 | + incrPatched: true, |
| 37 | + }, |
| 38 | + category: { |
| 39 | + primary: true, |
| 40 | + secondary: true, |
| 41 | + }, |
| 42 | +}; |
| 43 | + |
| 44 | +export type Profile = "check" | "debug" | "opt" | "doc"; |
| 45 | +export type Category = "primary" | "secondary"; |
| 46 | + |
| 47 | +export type CompileBenchmarkMap = Dict<{category: Category}>; |
| 48 | + |
| 49 | +export interface CompileBenchmarkDescription { |
| 50 | + name: string; |
| 51 | + category: Category; |
| 52 | +} |
| 53 | + |
| 54 | +export interface CompileBenchmarkComparison { |
| 55 | + benchmark: string; |
| 56 | + profile: Profile; |
| 57 | + scenario: string; |
| 58 | + comparison: StatComparison; |
| 59 | +} |
| 60 | + |
| 61 | +export interface CompileTestCase { |
| 62 | + benchmark: string; |
| 63 | + profile: Profile; |
| 64 | + scenario: string; |
| 65 | + category: Category; |
| 66 | +} |
| 67 | + |
| 68 | +export function computeCompileComparisonsWithNonRelevant( |
| 69 | + filter: CompileBenchmarkFilter, |
| 70 | + comparisons: CompileBenchmarkComparison[], |
| 71 | + benchmarkMap: CompileBenchmarkMap |
| 72 | +): TestCaseComparison<CompileTestCase>[] { |
| 73 | + function profileFilter(profile: Profile): boolean { |
| 74 | + if (profile === "check") { |
| 75 | + return filter.profile.check; |
| 76 | + } else if (profile === "debug") { |
| 77 | + return filter.profile.debug; |
| 78 | + } else if (profile === "opt") { |
| 79 | + return filter.profile.opt; |
| 80 | + } else if (profile === "doc") { |
| 81 | + return filter.profile.doc; |
| 82 | + } else { |
| 83 | + return true; |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + function scenarioFilter(scenario: string): boolean { |
| 88 | + if (scenario === "full") { |
| 89 | + return filter.scenario.full; |
| 90 | + } else if (scenario === "incr-full") { |
| 91 | + return filter.scenario.incrFull; |
| 92 | + } else if (scenario === "incr-unchanged") { |
| 93 | + return filter.scenario.incrUnchanged; |
| 94 | + } else if (scenario.startsWith("incr-patched")) { |
| 95 | + return filter.scenario.incrPatched; |
| 96 | + } else { |
| 97 | + // Unknown, but by default we should show things |
| 98 | + return true; |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + function categoryFilter(category: Category) { |
| 103 | + if (category === "primary" && !filter.category.primary) return false; |
| 104 | + if (category === "secondary" && !filter.category.secondary) return false; |
| 105 | + return true; |
| 106 | + } |
| 107 | + |
| 108 | + function shouldShowTestCase(comparison: TestCaseComparison<CompileTestCase>) { |
| 109 | + const name = `${comparison.testCase.benchmark} ${comparison.testCase.profile} ${comparison.testCase.scenario}`; |
| 110 | + const nameFilter = filter.name && filter.name.trim(); |
| 111 | + const nameFiltered = !nameFilter || name.includes(nameFilter); |
| 112 | + |
| 113 | + return ( |
| 114 | + profileFilter(comparison.testCase.profile) && |
| 115 | + scenarioFilter(comparison.testCase.scenario) && |
| 116 | + categoryFilter(comparison.testCase.category) && |
| 117 | + nameFiltered |
| 118 | + ); |
| 119 | + } |
| 120 | + |
| 121 | + let filteredComparisons = comparisons |
| 122 | + .map( |
| 123 | + (c: CompileBenchmarkComparison): TestCaseComparison<CompileTestCase> => { |
| 124 | + let testCase = { |
| 125 | + benchmark: c.benchmark, |
| 126 | + profile: c.profile, |
| 127 | + scenario: c.scenario, |
| 128 | + category: (benchmarkMap[c.benchmark] || {}).category || "secondary", |
| 129 | + }; |
| 130 | + return calculateComparison(c.comparison, testCase); |
| 131 | + } |
| 132 | + ) |
| 133 | + .filter((tc) => shouldShowTestCase(tc)); |
| 134 | + |
| 135 | + // Sort by name first, so that there is a canonical ordering |
| 136 | + // of test cases. This ensures the overall order is stable, even if |
| 137 | + // individual benchmarks have the same largestChange value. |
| 138 | + filteredComparisons.sort((a, b) => |
| 139 | + a.testCase.benchmark.localeCompare(b.testCase.benchmark) |
| 140 | + ); |
| 141 | + filteredComparisons.sort((a, b) => Math.abs(b.percent) - Math.abs(a.percent)); |
| 142 | + |
| 143 | + return filteredComparisons; |
| 144 | +} |
| 145 | + |
| 146 | +export function createCompileBenchmarkMap( |
| 147 | + data: CompareResponse |
| 148 | +): CompileBenchmarkMap { |
| 149 | + const benchmarks = {}; |
| 150 | + for (const benchmark of data.compile_benchmark_data) { |
| 151 | + benchmarks[benchmark.name] = { |
| 152 | + category: benchmark.category, |
| 153 | + }; |
| 154 | + } |
| 155 | + return benchmarks; |
| 156 | +} |
0 commit comments