Skip to content

Commit 4fd6d31

Browse files
authored
Merge pull request #1421 from rust-lang/significance-factor-infinity
Do not return NaN or Infinity significance factors
2 parents 9ae5b94 + 61ca7fe commit 4fd6d31

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

site/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub mod comparison {
194194
pub profile: String,
195195
pub scenario: String,
196196
pub is_relevant: bool,
197-
pub significance_factor: Option<f64>,
197+
pub significance_factor: f64,
198198
pub statistics: (f64, f64),
199199
}
200200
}

site/src/comparison.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ impl TestResultComparison {
11541154
!self.is_regression()
11551155
}
11561156

1157-
/// Whther the comparison yielded a statistically significant result
1157+
/// Whether the comparison yielded a statistically significant result
11581158
pub fn is_significant(&self) -> bool {
11591159
self.relative_change().abs() >= self.significance_threshold()
11601160
}
@@ -1168,11 +1168,17 @@ impl TestResultComparison {
11681168
}
11691169

11701170
/// This is a numeric magnitude of a particular change.
1171-
fn significance_factor(&self) -> Option<f64> {
1171+
fn significance_factor(&self) -> f64 {
11721172
let change = self.relative_change();
11731173
let threshold = self.significance_threshold();
1174-
// How many times the treshold this change is.
1175-
Some(change.abs() / threshold)
1174+
1175+
// How many times the threshold this change is.
1176+
let factor = change.abs() / threshold;
1177+
if factor.is_finite() {
1178+
factor
1179+
} else {
1180+
0.0
1181+
}
11761182
}
11771183

11781184
/// Whether the comparison is relevant or not.
@@ -1188,6 +1194,14 @@ impl TestResultComparison {
11881194
/// and the amount above the significance threshold.
11891195
pub fn magnitude(&self) -> Magnitude {
11901196
let change = self.relative_change().abs();
1197+
1198+
// When the significance threshold is very small, magnitude can become VeryLarge even though
1199+
// the change itself if incredibly small. So we deliberately return a VerySmall magnitude
1200+
// here to avoid marking such small result as being relevant.
1201+
if change < 0.0001 {
1202+
return Magnitude::VerySmall;
1203+
}
1204+
11911205
let threshold = self.significance_threshold();
11921206
let over_threshold = if change < threshold * 1.5 {
11931207
Magnitude::VerySmall

0 commit comments

Comments
 (0)