61

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?

4
  • 4
    Full code or at least a snippet would be ideal to give you more precice answers. Also: Have you tried running the code to see what it does? Commented Mar 21, 2018 at 10:17
  • 6
    isn't that iPython? Commented Mar 21, 2018 at 10:18
  • like here: stackoverflow.com/questions/32565829/… Commented Mar 21, 2018 at 10:19
  • Formatting changes. Commented Mar 21, 2018 at 11:35

1 Answer 1

95

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.