Skip to content
# %timeit
import numpy as np

Examining a single line of code

# single line of code
%timeit random_nums = np.random.rand(1000) #returns statistics on the run time

Modify the number of loops & runs

# Set the number of runs to 2 (-r2)
# Set the number of loops to 10 (-n10)
%timeit -r2 -n10 random_muns_2=np.random.rand(1000)
# multiple lines of code (%%)
%%timeit

nums=[]

for i in range(10):
    nums.append(i)

Save the output of a variable using -o