Skip to content

Commit a985302

Browse files
committed
Improve benchmark results and output.
1 parent 470bc15 commit a985302

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

benchmark/telco_fractions.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"""
4343

4444
import os
45+
from math import fsum
4546
from struct import unpack
4647
from time import time
4748

@@ -101,7 +102,8 @@ def run(cls):
101102

102103

103104
def main(n, cls=Fraction):
104-
run(cls) # warmup
105+
for _ in range(5):
106+
run(cls) # warmup
105107
times = []
106108
for _ in range(n):
107109
times.append(run(cls))
@@ -113,7 +115,7 @@ def main(n, cls=Fraction):
113115
parser = optparse.OptionParser(
114116
usage="%prog [options]",
115117
description="Test the performance of the Telco fractions benchmark")
116-
parser.add_option("-n", "--num_runs", action="store", type="int", default=12,
118+
parser.add_option("-n", "--num_runs", action="store", type="int", default=16,
117119
dest="num_runs", help="Number of times to repeat the benchmark.")
118120
parser.add_option("--use-decimal", action="store_true", default=False,
119121
dest="use_decimal", help="Run benchmark with Decimal instead of Fraction.")
@@ -130,3 +132,8 @@ def main(n, cls=Fraction):
130132
results = main(options.num_runs, num_class)
131133
for result in results:
132134
print(result)
135+
136+
print()
137+
results.sort()
138+
print('%.4f (mean)' % (fsum(results[1:-1]) / (len(results) - 2)))
139+
print('%.4f (median)' % (results[len(results) // 2]))

0 commit comments

Comments
 (0)