Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check reference value instead of k==0 #168

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/perfplot/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def __next__(self):
raise RuntimeError("Measured 0 ns for a function call. Try again?")

if self.equality_check:
if k == 0:
if reference is None:
reference = val
else:
try:
Expand Down Expand Up @@ -519,7 +519,7 @@ def callback():

for i in range(len(n_range)):
timings_s[i] = next(b)
# override n_rane in case it got overridden in next()
# override n_range in case it got overridden in next()
n_range = b.n_range

if show_progress:
Expand All @@ -539,17 +539,17 @@ def callback():
def plot(
*args,
time_unit: str = "s",
relative_to: int | None = None,
logx: Literal["auto"] | bool = "auto",
logy: Literal["auto"] | bool = "auto",
relative_to: int | None = None,
**kwargs,
):
out = bench(*args, **kwargs)
out.plot(
time_unit=time_unit,
relative_to=relative_to,
logx=logx,
logy=logy,
relative_to=relative_to,
)


Expand All @@ -575,17 +575,17 @@ def save(
transparent=True,
*args,
time_unit: str = "s",
relative_to: int | None = None,
logx: bool | Literal["auto"] = "auto",
logy: bool | Literal["auto"] = "auto",
relative_to: int | None = None,
**kwargs,
):
out = bench(*args, **kwargs)
out.save(
filename,
transparent,
time_unit=time_unit,
relative_to=relative_to,
logx=logx,
logy=logy,
relative_to=relative_to,
)
21 changes: 21 additions & 0 deletions tests/test_perfplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,24 @@ def times_reversed(a, b):
perfplot.show(
setup=setup, kernels=[times, times_reversed], n_range=[2**k for k in range(3)]
)


def test_exceed_time():
"""other functions should be checked for validity even if the first timed out"""
import time
def setup(n):
return np.random.rand(n)

def exceed_time(a):
time.sleep(0.5)
return 1

def in_time(a):
return 1

def in_time2(a):
return 1

b = perfplot.bench(
setup=setup, kernels=[exceed_time, in_time, in_time2], n_range=[2**k for k in range(3)], max_time=0.1
)