How do you time a single block of a Jupyter notebook with a single line of. Python code?
%time and %timeit don't cut it, but there must be a way to do this!
%time
%timeit
start = time.time()
## Create a Pandas dataframe from reader
df = pd.DataFrame(reader.readrows())
end = time.time()
print('Time taken ', end-start,' seconds')
Thanks, Nic
Use the cell magic %%timeit
(with two %) to time a whole jupyter cell, instead of just a single line. The cell magic must come before any python code in the cell.
http://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-timeit
In Jupyter Notebook, we have a magic function timeit
to time a whole cell.
%%timeit -n 10
#your code
Where 10 is the number of execution cycles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With