Calculate sample standard deviation (n-1 denominator). This is intended to match pytest-codspeed's computation, which uses python's statistics.stdev
(data: &[f64], mean: f64)
| 106 | /// This is intended to match pytest-codspeed's computation, which uses python's |
| 107 | /// statistics.stdev |
| 108 | fn sample_stdev(data: &[f64], mean: f64) -> f64 { |
| 109 | let n = data.len(); |
| 110 | if n <= 1 { |
| 111 | return 0.0; |
| 112 | } |
| 113 | let variance: f64 = data |
| 114 | .iter() |
| 115 | .map(|&t| { |
| 116 | let diff = t - mean; |
| 117 | diff * diff |
| 118 | }) |
| 119 | .sum::<f64>() |
| 120 | / (n - 1) as f64; |
| 121 | variance.sqrt() |
| 122 | } |
| 123 | |
| 124 | /// Calculate quantile with linear interpolation. |
| 125 | /// This is intended to match pytest-codspeed's computation, which uses python's |