Skip to content

Commit

Permalink
Improve benchmark accuracy and output.
Browse files Browse the repository at this point in the history
  • Loading branch information
scoder committed Apr 3, 2024
1 parent 572ba5f commit 987e4a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:

- name: Running benchmark
run: |
python benchmark/telco_fractions.py
python benchmark/telco_fractions.py -n 250
python benchmark/microbench.py create pydigits
Linux:
Expand Down Expand Up @@ -201,7 +201,7 @@ jobs:

- name: Running benchmark
run: |
python benchmark/telco_fractions.py
python benchmark/telco_fractions.py -n 250
python benchmark/microbench.py create pydigits
merge-wheels:
Expand Down
20 changes: 12 additions & 8 deletions benchmark/telco_fractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,20 @@ def run(cls):
def main(n, cls=Fraction):
for _ in range(5):
run(cls) # warmup
times = []
for _ in range(n):
times.append(run(cls))
times = [run(cls) for _ in range(n)]
return times


def percentile(values, percent):
return values[len(values) * percent // 100]


if __name__ == "__main__":
import optparse
parser = optparse.OptionParser(
usage="%prog [options]",
description="Test the performance of the Telco fractions benchmark")
parser.add_option("-n", "--num_runs", action="store", type="int", default=16,
parser.add_option("-n", "--num_runs", action="store", type="int", default=200,
dest="num_runs", help="Number of times to repeat the benchmark.")
parser.add_option("--use-decimal", action="store_true", default=False,
dest="use_decimal", help="Run benchmark with Decimal instead of Fraction.")
Expand All @@ -130,10 +132,12 @@ def main(n, cls=Fraction):
from fractions import Fraction as num_class

results = main(options.num_runs, num_class)
for result in results:
print(result)
#for result in results:
# print(result)
#print()

print()
results.sort()
print('%.4f (15%%)' % percentile(results, 15))
print('%.4f (median)' % percentile(results, 50))
print('%.4f (85%%)' % percentile(results, 85))
print('%.4f (mean)' % (fsum(results[1:-1]) / (len(results) - 2)))
print('%.4f (median)' % (results[len(results) // 2]))

0 comments on commit 987e4a9

Please sign in to comment.