回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我一直在比较numpy和Python列表理解在将随机数数组相乘时的相对效率。(python3.4/Spyder、Windows和Ubuntu)。在</p>
<p>正如人们所预期的,除了最小的数组之外,numpy的性能很快超过了列表理解,并且随着数组长度的增加,性能得到了预期的sigmoid曲线。但是乙状结肠远不是光滑的,我很难理解。在</p>
<p>显然,对于较短的数组长度,有一定数量的量化噪声,但我得到了意外的噪声结果,尤其是在窗口下。这些数字是不同数组长度的100次运行的平均值,所以应该会平滑掉所有的瞬态效应(所以我想)。在</p>
<p><a href="https://i.stack.imgur.com/uquMS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uquMS.png" alt="Performance characteristic"/></a></p>
<pre><code>Numpy and Python list performance comparison
</code></pre>
<p>下图显示了使用numpy将不同长度的数组与列表理解相乘的比率。在</p>
^{pr2}$
<p>所以我想我的问题是,有人能解释为什么结果,尤其是在窗户下,噪音这么大。我做了多次测试,但结果总是一模一样的。在</p>
<p>更新。在莱布隆·马斯克的建议下,我已经禁用了抓取收集。这使窗户的性能有点平滑,但曲线仍然是凹凸不平的。在</p>
<p><a href="https://i.stack.imgur.com/B0k4H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B0k4H.png" alt="Updated performance characteristic without garbage collection"/></a></p>
<pre><code>Numpy and Python list performance comparison
(Updated to remove garbage collection)
Array Length Windows Ubuntu
1 0.1 0.3
2 0.6 0.4
5 0.3 0.4
10 0.5 0.5
20 0.6 0.5
50 0.8 0.7
100 1.6 1.1
200 1.3 1.7
500 3.7 3.2
1,000 3.9 4.8
2,000 6.5 6.6
5,000 11.5 9.2
10,000 10.8 10.7
20,000 12.1 11.4
50,000 13.3 12.4
100,000 13.5 12.6
200,000 12.8 12.6
500,000 12.9 12.3
1,000,000 13.3 12.3
2,000,000 13.6 12.0
5,000,000 13.6 11.8
</code></pre>
<p>更新</p>
<p>根据@Sid的建议,我将其限制为在每台机器上的单个核心上运行。曲线稍微平滑一些(尤其是Linux),但是仍然有一些拐点和一些噪声,特别是在Windows下。在</p>
<p>(实际上,我最初要发布的是拐点,因为它们总是出现在相同的地方。)</p>
<pre><code>Numpy and Python list performance comparison
(Garbage collection disabled and running on 1 CPU)
Array Length Windows Ubuntu
1 0.3 0.3
2 0.0 0.4
5 0.5 0.4
10 0.6 0.5
20 0.3 0.5
50 0.9 0.7
100 1.0 1.1
200 2.8 1.7
500 3.7 3.3
1,000 3.3 4.7
2,000 6.5 6.7
5,000 11.0 9.6
10,000 11.0 11.1
20,000 12.7 11.8
50,000 12.9 12.8
100,000 14.3 13.0
200,000 12.6 13.1
500,000 12.6 12.6
1,000,000 13.0 12.6
2,000,000 13.4 12.4
5,000,000 13.6 12.2
</code></pre>
<p><a href="https://i.stack.imgur.com/JqXEY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JqXEY.png" alt="enter image description here"/></a></p>