Skip to content

Commit 541c48f

Browse files
authored
Merge pull request #19328 from palimondo/test-twice-commit-once
[benchmark] Report Quantiles from Benchmark_O and a TON of Gardening (take 2)
2 parents f630da9 + ce96538 commit 541c48f

File tree

7 files changed

+312
-206
lines changed

7 files changed

+312
-206
lines changed

benchmark/scripts/Benchmark_Driver

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ class BenchmarkDoctor(object):
434434
measurements = dict(
435435
[('{0} {1} i{2}{3}'.format(benchmark, o, i, suffix),
436436
self.driver.run(benchmark, num_samples=s, num_iters=i,
437-
verbose=True))
437+
verbose=True, measure_memory=True))
438438
for o in opts
439439
for s, i in run_args
440440
for suffix in list('abcde')

benchmark/scripts/compare_perf_tests.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class `ReportFormatter` creates the test comparison report in specified format.
3434
import sys
3535
from bisect import bisect, bisect_left, bisect_right
3636
from collections import namedtuple
37+
from decimal import Decimal, ROUND_HALF_EVEN
3738
from math import sqrt
3839

3940

@@ -141,20 +142,32 @@ def max(self):
141142
"""Maximum sampled value."""
142143
return self.samples[-1].runtime
143144

145+
def quantile(self, q):
146+
"""Return runtime of a sample nearest to the quantile.
147+
148+
Explicitly uses round-half-to-even rounding algorithm to match the
149+
behavior of numpy's quantile(interpolation='nearest') and quantile
150+
estimate type R-3, SAS-2. See:
151+
https://en.wikipedia.org/wiki/Quantile#Estimating_quantiles_from_a_sample
152+
"""
153+
index = int(Decimal((self.count - 1) * Decimal(q))
154+
.quantize(0, ROUND_HALF_EVEN))
155+
return self.samples[index].runtime
156+
144157
@property
145158
def median(self):
146159
"""Median sampled value."""
147-
return self.samples[self.count / 2].runtime
160+
return self.quantile(0.5)
148161

149162
@property
150163
def q1(self):
151164
"""First Quartile (25th Percentile)."""
152-
return self.samples[self.count / 4].runtime
165+
return self.quantile(0.25)
153166

154167
@property
155168
def q3(self):
156169
"""Third Quartile (75th Percentile)."""
157-
return self.samples[(self.count / 2) + (self.count / 4)].runtime
170+
return self.quantile(0.75)
158171

159172
@property
160173
def iqr(self):

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,10 +476,10 @@ def test_measure_10_independent_1s_benchmark_series(self):
476476
# 5x i1 series, with 300 μs runtime its possible to take 4098
477477
# samples/s, but it should be capped at 2k
478478
([(_run('B1', num_samples=2048, num_iters=1,
479-
verbose=True), _PTR(min=300))] * 5) +
479+
verbose=True, measure_memory=True), _PTR(min=300))] * 5) +
480480
# 5x i2 series
481481
([(_run('B1', num_samples=2048, num_iters=2,
482-
verbose=True), _PTR(min=300))] * 5)
482+
verbose=True, measure_memory=True), _PTR(min=300))] * 5)
483483
))
484484
doctor = BenchmarkDoctor(self.args, driver)
485485
with captured_output() as (out, _):

benchmark/scripts/test_compare_perf_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ def test_computes_five_number_summary(self):
7575
self.samples, (1000, 1000, 1000, 1000, 1000))
7676
self.samples.add(Sample(2, 1, 1100))
7777
self.assertEqualFiveNumberSummary(
78-
self.samples, (1000, 1000, 1100, 1100, 1100))
78+
self.samples, (1000, 1000, 1000, 1100, 1100))
7979
self.samples.add(Sample(3, 1, 1050))
8080
self.assertEqualFiveNumberSummary(
81-
self.samples, (1000, 1000, 1050, 1050, 1100))
81+
self.samples, (1000, 1000, 1050, 1100, 1100))
8282
self.samples.add(Sample(4, 1, 1025))
8383
self.assertEqualFiveNumberSummary(
84-
self.samples, (1000, 1025, 1050, 1100, 1100))
84+
self.samples, (1000, 1025, 1050, 1050, 1100))
8585
self.samples.add(Sample(5, 1, 1075))
8686
self.assertEqualFiveNumberSummary(
8787
self.samples, (1000, 1025, 1050, 1075, 1100))
@@ -156,11 +156,12 @@ def test_excludes_outliers_zero_IQR(self):
156156
self.samples.add(Sample(0, 2, 23))
157157
self.samples.add(Sample(1, 2, 18))
158158
self.samples.add(Sample(2, 2, 18))
159+
self.samples.add(Sample(3, 2, 18))
159160
self.assertEquals(self.samples.iqr, 0)
160161

161162
self.samples.exclude_outliers()
162163

163-
self.assertEquals(self.samples.count, 2)
164+
self.assertEquals(self.samples.count, 3)
164165
self.assertEqualStats(
165166
(self.samples.min, self.samples.max), (18, 18))
166167

@@ -368,7 +369,6 @@ def test_parse_results_verbose(self):
368369
Sample 0,11812
369370
Measuring with scale 90.
370371
Sample 1,13898
371-
Measuring with scale 91.
372372
Sample 2,11467
373373
1,AngryPhonebook,3,11467,13898,12392,1315,11812
374374
Running Array2D for 3 samples.
@@ -388,7 +388,7 @@ def test_parse_results_verbose(self):
388388
)
389389
self.assertEquals(r.num_samples, r.samples.num_samples)
390390
self.assertEquals(results[0].samples.all_samples,
391-
[(0, 78, 11812), (1, 90, 13898), (2, 91, 11467)])
391+
[(0, 78, 11812), (1, 90, 13898), (2, 90, 11467)])
392392

393393
r = results[1]
394394
self.assertEquals(

0 commit comments

Comments
 (0)