Skip to content

Commit

Permalink
Merge pull request #93 from nschloe/fewer-evals
Browse files Browse the repository at this point in the history
Fewer evals
  • Loading branch information
nschloe committed Dec 7, 2020
2 parents 7be5087 + de0fe7d commit 68c9842
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tag:
upload: clean
@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
# https://stackoverflow.com/a/58756491/353337
python3 -m pep517.build --source --binary .
python3 -m build --sdist --wheel .
twine upload dist/*

publish: tag upload
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ perfplot.show(
labels=["c_", "stack", "vstack", "column_stack", "concat"],
n_range=[2 ** k for k in range(25)],
xlabel="len(a)",
# logx=False,
# logy=False,
# More optional arguments with their default values:
# logx="auto", # set to True or False to force scaling
# logy="auto",
Expand Down
2 changes: 2 additions & 0 deletions perfplot/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class PerfplotError(Exception):
pass
39 changes: 24 additions & 15 deletions perfplot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from rich.progress import Progress
from rich.table import Table

from .exceptions import PerfplotError

matplotlib.style.use(dufte.style)

# Orders of Magnitude for SI time units in {unit: magnitude} format
Expand Down Expand Up @@ -41,9 +43,11 @@ def _auto_time_unit(min_time_ns):
"""
# Converting minimum timing into seconds from nanoseconds
t_s = min_time_ns * si_time["ns"]
time_unit = None
for time_unit, magnitude in si_time.items():
if t_s >= magnitude:
break
assert time_unit is not None
return time_unit


Expand Down Expand Up @@ -195,29 +199,32 @@ def bench(
task2 = progress.add_task("Kernels", total=len(kernels))
for i, n in enumerate(n_range):
data = setup(n)
if equality_check:
relative_to = kernels[0](data)

if show_progress:
progress.reset(task2)

for k, kernel in enumerate(kernels):
if equality_check:
try:
is_equal = equality_check(relative_to, kernel(data))
except TypeError:
print(
"Error in equality_check. "
"Try setting equality_check=None."
)
raise
if k == 0:
reference = kernel(data)
else:
assert (
is_equal
), f"Equality check failure. ({labels[0]}, {labels[k]})"
try:
is_equal = equality_check(reference, kernel(data))
except TypeError:
raise PerfplotError(
"Error in equality_check. "
"Try setting equality_check=None."
)
else:
if not is_equal:
raise PerfplotError(
"Equality check failure. "
f"({labels[0]}, {labels[k]})"
)

# First try with one repetition only. If this doesn't exceed the
# target time, append as many repeats as the first measurements
# suggests. If the kernel is fast, the measurement with one
# target time, append as many repetitions as the first measurement
# suggests. If the kernel is fast, the measurement with one
# repetition only can be somewhat off, but most of the time it's
# good enough.
remaining_time = int(target_time_per_measurement / si_time["ns"])
Expand Down Expand Up @@ -255,6 +262,7 @@ def _b(data, kernel, repeat, timer, is_ns_timer, resolution):
number = 1
required_timing = 10 * resolution
min_timing = 0
tm = None

while min_timing <= required_timing:
tm = numpy.array(
Expand Down Expand Up @@ -289,6 +297,7 @@ def _b(data, kernel, repeat, timer, is_ns_timer, resolution):

number = int(factor * number) + 1

assert tm is not None
# Only return the minimum time; everthing else just measures how slow the system can
# go.
return numpy.min(tm), numpy.sum(tm)
Expand Down
5 changes: 1 addition & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = perfplot
version = 0.8.7
version = 0.8.8
author = Nico Schlömer
author_email = nico.schloemer@gmail.com
description = Performance plots for Python code snippets
Expand Down Expand Up @@ -38,6 +38,3 @@ install_requires =
numpy
rich
python_requires = >=3.6
setup_requires =
setuptools>=42
wheel

0 comments on commit 68c9842

Please sign in to comment.