[IPython-User] question about cell magic

Fernando Perez fperez.net@gmail....
Thu Jun 21 15:36:08 CDT 2012

On Thu, Jun 21, 2012 at 1:26 PM, Zoltán Vörös <zvoros@gmail.com> wrote:
> 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

That's very strange and I can't reproduce your problem, it works
perfectly OK for me here:

In [1]: %%timeit
   ...: x = 0
   ...: for i in range(100000):
   ...:     x += i**2
100 loops, best of 3: 17.3 ms per loop

This was tested at the console, qt console and notebook and it works
the same in all three cases.

I have no idea how what you report can even be happening, as both
%timeit and %%timeit use the exact same codepaths, only a tiny amount
at the start is different.

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

Well, we report the statistics as computed by the stdlib timeit
module, which is what we use.  These are loops executing your entire
code, not loops inside your code.  Since that's how the stdlib module
was designed and works by default, I'd rather stick to its API.



More information about the IPython-User mailing list