Skip to content

Commit 8d37b08

Browse files
authored
Merge pull request #1919 from s7tya/feat/use-regex-filter
Change the filter from includes() to a regex match
2 parents c96118c + bf48f16 commit 8d37b08

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

site/frontend/src/pages/compare/compile/common.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {BenchmarkFilter, CompareResponse, StatComparison} from "../types";
22
import {calculateComparison, TestCaseComparison} from "../data";
3+
import {benchmarkNameMatchesFilter} from "../shared";
34

45
export type CompileBenchmarkFilter = {
56
profile: {
@@ -158,17 +159,13 @@ export function computeCompileComparisonsWithNonRelevant(
158159
}
159160

160161
function shouldShowTestCase(comparison: TestCaseComparison<CompileTestCase>) {
161-
const name = `${comparison.testCase.benchmark} ${comparison.testCase.profile} ${comparison.testCase.scenario} ${comparison.testCase.backend}`;
162-
const nameFilter = filter.name && filter.name.trim();
163-
const nameFiltered = !nameFilter || name.includes(nameFilter);
164-
165162
return (
166163
profileFilter(comparison.testCase.profile) &&
167164
scenarioFilter(comparison.testCase.scenario) &&
168165
backendFilter(comparison.testCase.backend) &&
169166
categoryFilter(comparison.testCase.category) &&
170167
artifactFilter(benchmarkMap[comparison.testCase.benchmark] ?? null) &&
171-
nameFiltered
168+
benchmarkNameMatchesFilter(comparison.testCase.benchmark, filter.name)
172169
);
173170
}
174171

site/frontend/src/pages/compare/runtime/common.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {BenchmarkFilter, StatComparison} from "../types";
22
import {calculateComparison, TestCaseComparison} from "../data";
3+
import {benchmarkNameMatchesFilter} from "../shared";
34

45
export interface RuntimeTestCase {
56
benchmark: string;
@@ -22,10 +23,13 @@ export function computeRuntimeComparisonsWithNonRelevant(
2223
filter: RuntimeBenchmarkFilter,
2324
comparisons: RuntimeBenchmarkComparison[]
2425
): TestCaseComparison<RuntimeTestCase>[] {
25-
function shouldShowTestCase(comparison: TestCaseComparison<RuntimeTestCase>) {
26-
const name = comparison.testCase.benchmark;
27-
const nameFilter = filter.name && filter.name.trim();
28-
return !nameFilter || name.includes(nameFilter);
26+
function shouldShowTestCase(
27+
comparison: TestCaseComparison<RuntimeTestCase>
28+
): boolean {
29+
return benchmarkNameMatchesFilter(
30+
comparison.testCase.benchmark,
31+
filter.name
32+
);
2933
}
3034

3135
let filteredComparisons = comparisons

site/frontend/src/pages/compare/shared.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,18 @@ export function getBoolOrDefault(
7878
}
7979
return defaultValue;
8080
}
81+
82+
export function benchmarkNameMatchesFilter(
83+
benchmarkName: string,
84+
filterName: string | null
85+
): boolean {
86+
if (!filterName) return true;
87+
const trimmedFilterName = filterName.trim();
88+
// Use `includes()` when a regex is not valid.
89+
try {
90+
const filterRegex = new RegExp(trimmedFilterName);
91+
return filterRegex.test(benchmarkName);
92+
} catch (e) {
93+
return benchmarkName.includes(trimmedFilterName);
94+
}
95+
}

0 commit comments

Comments
 (0)