Quickly time your loops with a single line of code. Take code like this
for i in arr:
# do something
and time it like this
from looptimer import timing
for i in timing(arr):
# do something
arr = range(10)
for i in timing(arr):
time.sleep(1)
Iteration 0 took 1.0011s
Iteration 1 took 1.0011s
Iteration 2 took 1.0011s
Iteration 3 took 1.0008s
Iteration 4 took 1.0008s
Total runtime: 5.0068s
Average runtime per loop: 1.0010s
Shortest loop: 1.0008s
Longest loop: 1.0011s
Print every N iterations using the every_n
parameter.
arr = range(5)
for i in timing(arr, every_n=2): # prints every 2 iterations
time.sleep(1)
Print every % of your way through the data using the every_fraction
parameter.
arr = range(5)
for i in timing(arr, every_fraction=0.5): # prints every 50% of the way through the data
time.sleep(1)