Numpy性能与矢量长度无关

时间:2016-05-16 20:44:45

标签: python performance numpy

我在numpy的表现上遇到了一些麻烦。似乎许多操作的性能几乎完全独立于向量长度:

In [23]: y1 = np.random.randn(3)

In [24]: y2 = np.random.randn(300)

In [25]: %timeit np.mean(y1)
The slowest run took 9.65 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 4.91 µs per loop

In [26]: %timeit np.mean(y2)
The slowest run took 9.58 times longer than the fastest. This could mean that an intermediate result is being cached.
100000 loops, best of 3: 5.07 µs per loop

In [27]: %timeit np.median(y1)
The slowest run took 5.28 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 23.6 µs per loop

In [28]: %timeit np.median(y2)
The slowest run took 4.91 times longer than the fastest. This could mean that an intermediate result is being cached.
10000 loops, best of 3: 25.7 µs per loop

In [29]: %timeit np.max(y1)
The slowest run took 19.66 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 1.91 µs per loop

In [30]: %timeit np.max(y2)
The slowest run took 19.95 times longer than the fastest. This could mean that an intermediate result is being cached.
1000000 loops, best of 3: 1.98 µs per loop

timeit有什么问题吗?

0 个答案:

没有答案