Skip to content

Commit d694873

Browse files
committed
handle 0 metrics to avoid NaNs during sorting
1 parent 3ba1b59 commit d694873

File tree

1 file changed

+16
-1
lines changed
  • site/frontend/src/pages/compare

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,22 @@ export function computeTestCasesWithNonRelevant(
9090
.map((c: CompileBenchmarkComparison): TestCase => {
9191
const datumA = c.statistics[0];
9292
const datumB = c.statistics[1];
93-
const percent = 100 * ((datumB - datumA) / datumA);
93+
94+
// In the vast majority of cases, we can do the proportional change calculation. However, some
95+
// metrics can be zero. If the initial value is 0, we can't compute the new value as a
96+
// percentage change of the old one. If both values are 0, we can say the change is also 0%.
97+
// If the new value is not 0, the percentage is not really meaningful, but we can say it's 100%.
98+
let percent;
99+
if (datumA === 0) {
100+
if (datumB === 0) {
101+
percent = 0;
102+
} else {
103+
percent = 100;
104+
}
105+
} else {
106+
percent = 100 * ((datumB - datumA) / datumA);
107+
}
108+
94109
return {
95110
benchmark: c.benchmark,
96111
profile: c.profile,

0 commit comments

Comments
 (0)