Time the performance by timeit and cell magic
Goal¶
This post aims to introduce how to measure the running time of your code or function by using timeit
module and cell magic command %%time
and %%timeit
.
Reference *Time a Python Function
Libraries¶
In [1]:
import pandas as pd
import timeit
Measure a literal code¶
In [2]:
timeit.timeit('2**10')
Out[2]:
Measure the execution time for a function¶
In [4]:
def execute_abc(x=10):
return 2 ** 10
In [7]:
timeit.timeit(execute_abc)
Out[7]:
Measure the time by using Cell Magic in Jupyter Notebook¶
In [3]:
%%time
2**10
Out[3]:
In [9]:
%timeit 2**10