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.
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.
Did you try %timeit
as the first line in the cell? I'm not sure whether that would work.
Another option is to write a dummy program that calls your other program, like def foo(): return my_program(n)
and then do timeit on foo.
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. :)
Please start posting anonymously - your entry will be published after you log in or create a new account.
Asked: 2010-12-06 08:35:27 +0100
Seen: 526 times
Last updated: Dec 08 '10