为什么 struct.pack 的性能变化如此之大?
Why does struct.pack have such high variability in performance?
我在测试 struct.pack
的性能时得到以下结果:
In [3]: %timeit pack('dddd', 1.0, 1.0, 1.0, 1.0)
The slowest run took 578.59 times longer than the fastest. This could
mean that an intermediate result is being cached
1000000 loops, best of 3: 197 ns per loop
为什么最慢的运行慢了578倍? pack 是否在做一些内部缓存,或者这是某种 CPU 级缓存的结果,还是其他什么?
我在测试 struct.pack
的性能时得到以下结果:
In [3]: %timeit pack('dddd', 1.0, 1.0, 1.0, 1.0)
The slowest run took 578.59 times longer than the fastest. This could
mean that an intermediate result is being cached
1000000 loops, best of 3: 197 ns per loop
为什么最慢的运行慢了578倍? pack 是否在做一些内部缓存,或者这是某种 CPU 级缓存的结果,还是其他什么?