Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython: turn off %timeit message about "This could mean that an intermediate result is being cached"

Tags:

ipython

Since upgrading to IPython version 3 (I have 3.1.0), every time I use the %timeit command, it prints "The slowest run took [number] times longer than the fastest. This could mean that an intermediate result is being cached" before printing the timing results. This happens even for very simple operations. For example:

In [4]: x = 5

In [5]: %timeit x
The slowest run took 53.99 times longer than the fastest. This could mean that an intermediate result is being cached 
100000000 loops, best of 3: 19.8 ns per loop

and:

In [17]: %timeit 22 + 1
The slowest run took 106.15 times longer than the fastest. This could mean that an intermediate result is being cached 
100000000 loops, best of 3: 12.2 ns per loop

There are only a few cases where I can get it to not happen, like:

In [15]: %timeit 5
100000000 loops, best of 3: 8.37 ns per loop

I understand that there's probably some caching going on at some level (for example as explained in this other answer), but the message is distracting and not really useful. Is there any way to turn it off?

like image 758
Avril Avatar asked Nov 17 '25 17:11

Avril


1 Answers

%timeit -q will be silent, and the -o option will return the result. This is slightly different, but should do the trick.

like image 72
Matt Avatar answered Nov 21 '25 08:11

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!