IPython:关闭%timeit消息“这可能意味着正在缓存中间结果”

时间:2015-07-20 17:19:09

标签: ipython

自升级到IPython版本3(我有3.1.0)以来,每次使用%timeit命令时,都会打印出“最慢的运行时间比最快的时间长了几倍。这可能意味着在打印定时结果之前,正在缓存中间结果。即使是非常简单的操作也会发生这种例如:

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

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

只有少数几种情况我不能发生,例如:

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

据我所知,某些级别可能正在进行某些缓存(例如OpenMP specification中所述),但该消息令人分心并且不太有用。有没有办法把它关掉?

1 个答案:

答案 0 :(得分:5)

%timeit -q将保持沉默,-o选项将返回结果。这略有不同,但应该做到这一点。

相关问题