[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:
Pavol Vaskovic
2018-08-30 06:52:58 +02:00
parent ab3e6122c0
commit e48b5fdb34
3 changed files with 12 additions and 7 deletions

View File

@@ -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):