Skip to content

Commit

Permalink
bench: tweak script
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarrison committed Sep 12, 2024
1 parent 4330088 commit ef0b391
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions scripts/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,25 @@ def func():
res['firsttime'] = t1

if time:
nrep, tot_time = timeit.Timer(func).autorange()
nrep, tot_time = autorange(timeit.Timer(func))
t = tot_time / nrep
res['time'] = t

return res


def autorange(timer: timeit.Timer, min_time=2.0):
"""Adapted from timeit.Timer.autorange"""
i = 1
while True:
for j in 1, 2, 5:
number = i * j
time_taken = timer.timeit(number)
if time_taken >= min_time:
return (number, time_taken)
i *= 10


def get_plot_kwargs(method, nthread_max=NTHREAD_MAX):
if method == 'finufft_par':
label = (
Expand Down Expand Up @@ -231,7 +243,7 @@ def bench(

res = run_one(method, N, Nf, dtype, batch_size=batch_size)

print(f'{method} took {res["time"]:.4g} sec ({Nf=})')
print(f'{method} took {res["time"]:8.4g} sec ({sweep}={eval(sweep):d})')
all_res.append(res)

for res in all_res:
Expand Down

0 comments on commit ef0b391

Please sign in to comment.