55

What does %%time mean in python? I am using python 3 and have some source code containing

%%time

Does this call the time module? or does it have another function?

rlandster
  • 7,294
  • 14
  • 58
  • 96
JZF
  • 663
  • 1
  • 5
  • 8

1 Answers1

85

%%time is a magic command. It's a part of IPython.

%%time prints the wall time for the entire cell whereas %time gives you the time for first line only

Using %%time or %time prints 2 values:

  1. CPU Times
  2. Wall Time

You can read more about it in the documentation

m_____z
  • 1,521
  • 13
  • 22
Vedant Shetty
  • 1,577
  • 13
  • 14
  • 2
    When I use %%time in the beginning of the cell and run the particular cell, I get only the Wall time and not the CPU time. Also, could you clarify if the wall times and cpu times are expected to change every execution (without changing the code)? – bobthebuilder May 14 '20 at 06:57
  • 1
    @bobthebuilder I didn't have the same problem. Also, for your 2nd question, your computer/server might be idle or busy from time to time, therefore the CPU times are expected to vary in each execution. – Raptor Mar 07 '23 at 14:09