pythontimejupyter-notebookdifferencemagic-command

Difference between %time and %%time in Jupyter Notebook


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


Solution

  • %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