time in notebook
Hello!
Could you help me? I need to know the time of a sage program written in the notebook, but when I use the timeit command, it doesn't work if I use "for" iterators in the program.
In my case the following syntax works:
%time
for i in range(0,10):
command1
command2
...
The working example:
%time
time print("The first line took:")
time print("\nThe second line took:")
for i in range(0,10):
sleep(1)
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.01 s, Wall time: 10.04 s
Hope, that helps. :)
However, this doesn't do what timeit does, which is to do it over several iterations. For instance, in the first line we really want `sage: timeit('print("The first line took:")') 625 loops, best of 3: 734 ns per loop`
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 14 years ago
Seen: 556 times
Last updated: Dec 08 '10