[IPython-User] question about cell magic
Thu Jun 21 15:26:39 CDT 2012
On 06/21/2012 09:58 PM, Thomas Kluyver wrote:
> On 21 June 2012 20:03, Zoltán Vörös<email@example.com> wrote:
>> However, the following won't work
>> x = 0
>> for i in range(100000):
>> x += i**2
> It's working fine for me. What happens when you try it?
When I run the code above, the kernel returns immediately, and it does
not produce any output. On the other hand, if I run this
%%timeit x = 0
for i in range(100000):
x += i**2
the output is
100 loops, best of 3: 16.1 ms per loop
which is reasonable, given that I have to wait about 2 seconds for any printout. It seems to me that in the first case, nothing happens at all, but even if it does, I really would not expect such a big difference. (Besides, there is no trace of what is happening.) I have tried it with the latest version from master. The browser is chrome, though, that shouldn't matter, I guess.
As a general remark, I am also wondering whether the output for %%timeit could be different. For %timeit, it is OK, because there is only a single statement that can be timed, but here, it is not immediately clear what the 'loop' means, for there might be many loops in the cell. I have the feeling that the output is a bit misleading.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the IPython-User