3

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?

Community
  • 1
  • 1
Avril
  • 813
  • 1
  • 9
  • 20

1 Answers1

7

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

Student
  • 1,197
  • 4
  • 22
  • 39
Matt
  • 27,170
  • 6
  • 80
  • 74
  • Oh cool, I didn't even know the magic functions could take flags or return results. I'll try to see if there's a way to give it default flags without typing them every time, but this solution is definitely better than nothing. – Avril Jul 20 '15 at 18:42