Skip to content

Commit

Permalink
CLN: add typing to autotimeit.py
Browse files Browse the repository at this point in the history
  • Loading branch information
qwhelan committed Jan 18, 2020
1 parent 33d4bac commit 37110cf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions bottleneck/benchmark/autotimeit.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import timeit
from typing import Tuple


def autotimeit(stmt, setup="pass", repeat=3, mintime=0.2):
def autotimeit(
stmt: str, setup: str = "pass", repeat: int = 3, mintime: float = 0.2
) -> float:
timer = timeit.Timer(stmt, setup)
number, time1 = autoscaler(timer, mintime)
time2 = timer.repeat(repeat=repeat - 1, number=number)
return min(time2 + [time1]) / number


def autoscaler(timer, mintime):
def autoscaler(timer: timeit.Timer, mintime: float) -> Tuple[int, float]:
number = 1
for i in range(12):
for _ in range(12):
time = timer.timeit(number)
if time > mintime:
return number, time
Expand Down

0 comments on commit 37110cf

Please sign in to comment.