Difference between %time and %%time in Jupyter Notebook

Viewed 2565

What is the difference between %time and %%time in a Jupyter Notebook Cell?

1 Answers

%time measures execution time of the next line.

%%time measures execution time of the whole cell.

For instance:

%time
a = 1
time.sleep(5)

CPU times: user 8 µs, sys: 0 ns, total: 8 µs Wall time: 16.9 µs

%%time
a = 1
time.sleep(5)

CPU times: user 1.13 ms, sys: 2.11 ms, total: 3.24 ms Wall time: 5 s

Related