First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 14 years ago

v_2e gravatar image

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

click to hide/show revision 2
No.2 Revision

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