Revision history [back]

As far as I know,

%time
command1
command2
...


works for timing the execution of the whole cell. Meanwhile, there is an inline

time


statement, which one may put at the beginning of the line like this:

time print("The first line took:")


To compare how these two tools work, you may try executing the following cell:

%time
time print("The first line took:")
time print("\nThe second line took:")
print("\nAltogether took:")


The output should look like this:

The first line took:
Time: CPU 0.00 s, Wall: 0.00 s

The second line took:
Time: CPU 0.00 s, Wall: 0.00 s

Altogether took:
CPU time: 0.00 s,  Wall time: 0.00 s


Hope that helps. :)

As far as I know,

%time
command1
command2
...


works for timing the execution of the whole cell. Meanwhile, there is an inline

time


statement, which one may put at the beginning of the line like this:

time print("The first line took:")


To compare how these two tools work, you may try executing the following cell:

%time
time print("The first line took:")
time print("\nThe second line took:")
print("\nAltogether took:")


The output should look like this:

 The first line took:
took: Time: CPU 0.00 s, Wall: 0.00 s
The second line took:
took: Time: CPU 0.00 s, Wall: 0.00 s
Altogether took:
took: CPU time: 0.00 s,  Wall time: 0.00 s

s

Hope that helps. :)