mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[benchmark] Fix index computation for quantiles
Turns out that both the old code in `DriverUtils` that computed median, as well as newer quartiles in `PerformanceTestSamples` had off-by-1 error. It trully is the 3rd of the 2 hard things in computer science!
This commit is contained in:
@@ -141,20 +141,24 @@ class PerformanceTestSamples(object):
|
||||
"""Maximum sampled value."""
|
||||
return self.samples[-1].runtime
|
||||
|
||||
def _quantile_index(self, q, i):
|
||||
"""Return index of the element nearest to the i-th q-quantile."""
|
||||
return int(round((self.count - 1) / float(q) * float(i)))
|
||||
|
||||
@property
|
||||
def median(self):
|
||||
"""Median sampled value."""
|
||||
return self.samples[self.count / 2].runtime
|
||||
return self.samples[self._quantile_index(2, 1)].runtime
|
||||
|
||||
@property
|
||||
def q1(self):
|
||||
"""First Quartile (25th Percentile)."""
|
||||
return self.samples[self.count / 4].runtime
|
||||
return self.samples[self._quantile_index(4, 1)].runtime
|
||||
|
||||
@property
|
||||
def q3(self):
|
||||
"""Third Quartile (75th Percentile)."""
|
||||
return self.samples[(self.count / 2) + (self.count / 4)].runtime
|
||||
return self.samples[self._quantile_index(4, 3)].runtime
|
||||
|
||||
@property
|
||||
def iqr(self):
|
||||
|
||||
Reference in New Issue
Block a user