<p dir="auto">Executing same code in 2 machines</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Python 3.6.5
numpy==1.14.4"><pre class="notranslate"><code class="notranslate">Python 3.6.5
numpy==1.14.4
</code></pre></div>
<p dir="auto">and</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Python 3.7.6
numpy==1.17.3"><pre class="notranslate"><code class="notranslate">Python 3.7.6
numpy==1.17.3
</code></pre></div>
<p dir="auto">the time it takes in 1.14 is near 3 times faster.  Downgrading to 1.14 from 1.17 confirms it:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/895596/75329664-4bdc2c00-5880-11ea-85a2-36e8bcc0a688.jpg"><img src="https://user-images.githubusercontent.com/895596/75329664-4bdc2c00-5880-11ea-85a2-36e8bcc0a688.jpg" alt="IMAGE 2020-02-26 10:10:51" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/895596/75329673-50a0e000-5880-11ea-8efa-3111a9091229.jpg"><img src="https://user-images.githubusercontent.com/895596/75329673-50a0e000-5880-11ea-8efa-3111a9091229.jpg" alt="IMAGE 2020-02-26 10:10:54" style="max-width: 100%;"></a></p>
<p dir="auto">Hi, I am seeing a performance regression when migrating from numpy 1.11.0 to 1.16.4. The performance decrease seems to be spread across multiple numpy functions, but here is a simple example which shows a consistent performance difference:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from __future__ import absolute_import
from __future__ import division

import numpy as np
import cProfile


def mean_test(array):
    return np.mean(array)


def mean_benchmark():
    my_array = np.ones((3, 3), dtype=np.float32)
    for _ in range(7600):
        mean_test(my_array)


if __name__ == &quot;__main__&quot;:
    cProfile.run('mean_benchmark()', sort='cumtime')"><pre lang="from" class="notranslate"><code class="notranslate">from __future__ import absolute_import
from __future__ import division

import numpy as np
import cProfile


def mean_test(array):
    return np.mean(array)


def mean_benchmark():
    my_array = np.ones((3, 3), dtype=np.float32)
    for _ in range(7600):
        mean_test(my_array)


if __name__ == "__main__":
    cProfile.run('mean_benchmark()', sort='cumtime')
</code></pre></div>
<p dir="auto">If I run this 3 times, and pick the best run out of the 3, I get:</p>
<p dir="auto">For numpy 1.11.0:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="         91207 function calls in 0.125 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.125    0.125 &lt;string&gt;:1(&lt;module&gt;)
        1    0.003    0.003    0.125    0.125 numpy_benchmark.py:113(mean_benchmark)
     7600    0.004    0.000    0.121    0.000 numpy_benchmark.py:9(mean_test)
     7600    0.007    0.000    0.118    0.000 fromnumeric.py:2796(mean)
     7600    0.055    0.000    0.110    0.000 _methods.py:53(_mean)
     7600    0.017    0.000    0.020    0.000 _methods.py:43(_count_reduce_items)
     7600    0.020    0.000    0.020    0.000 {method 'reduce' of 'numpy.ufunc' objects}
     7600    0.005    0.000    0.006    0.000 numeric.py:484(asanyarray)
    15200    0.004    0.000    0.004    0.000 {isinstance}
     7600    0.003    0.000    0.003    0.000 {issubclass}
     7601    0.003    0.000    0.003    0.000 {range}
     7600    0.002    0.000    0.002    0.000 {hasattr}
     7600    0.002    0.000    0.002    0.000 {numpy.core.multiarray.array}
        1    0.000    0.000    0.000    0.000 numeric.py:148(ones)
        1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.copyto}
        1    0.000    0.000    0.000    0.000 {numpy.core.multiarray.empty}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}"><pre class="notranslate">         <span class="pl-c1">91207</span> <span class="pl-s1">function</span> <span class="pl-s1">calls</span> <span class="pl-c1">in</span> <span class="pl-c1">0.125</span> <span class="pl-s1">seconds</span>

   <span class="pl-v">Ordered</span> <span class="pl-s1">by</span>: <span class="pl-s1">cumulative</span> <span class="pl-s1">time</span>

   <span class="pl-s1">ncalls</span>  <span class="pl-s1">tottime</span>  <span class="pl-s1">percall</span>  <span class="pl-s1">cumtime</span>  <span class="pl-s1">percall</span> <span class="pl-s1">filename</span>:<span class="pl-en">lineno</span>(<span class="pl-s1">function</span>)
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.125</span>    <span class="pl-c1">0.125</span> <span class="pl-c1">&lt;</span><span class="pl-s1">string</span><span class="pl-c1">&gt;</span>:<span class="pl-c1">1</span>(<span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>)
        <span class="pl-c1">1</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.125</span>    <span class="pl-c1">0.125</span> <span class="pl-s1">numpy_benchmark</span>.<span class="pl-s1">py</span>:<span class="pl-c1">113</span>(<span class="pl-s1">mean_benchmark</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.121</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">numpy_benchmark</span>.<span class="pl-s1">py</span>:<span class="pl-c1">9</span>(<span class="pl-s1">mean_test</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.007</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.118</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">fromnumeric</span>.<span class="pl-s1">py</span>:<span class="pl-c1">2796</span>(<span class="pl-s1">mean</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.055</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.110</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">_methods</span>.<span class="pl-s1">py</span>:<span class="pl-c1">53</span>(<span class="pl-s1">_mean</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.017</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.020</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">_methods</span>.<span class="pl-s1">py</span>:<span class="pl-c1">43</span>(<span class="pl-s1">_count_reduce_items</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.020</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.020</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">method</span> <span class="pl-s">'reduce'</span> <span class="pl-s1">of</span> <span class="pl-s">'numpy.ufunc'</span> <span class="pl-s1">objects</span>}
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.005</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.006</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">numeric</span>.<span class="pl-s1">py</span>:<span class="pl-c1">484</span>(<span class="pl-s1">asanyarray</span>)
    <span class="pl-c1">15200</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">isinstance</span>}
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">issubclass</span>}
     <span class="pl-c1">7601</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">range</span>}
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">hasattr</span>}
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">numpy</span>.<span class="pl-s1">core</span>.<span class="pl-s1">multiarray</span>.<span class="pl-s1">array</span>}
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">numeric</span>.<span class="pl-s1">py</span>:<span class="pl-c1">148</span>(<span class="pl-s1">ones</span>)
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">numpy</span>.<span class="pl-s1">core</span>.<span class="pl-s1">multiarray</span>.<span class="pl-s1">copyto</span>}
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">numpy</span>.<span class="pl-s1">core</span>.<span class="pl-s1">multiarray</span>.<span class="pl-s1">empty</span>}
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">method</span> <span class="pl-s">'disable'</span> <span class="pl-s1">of</span> <span class="pl-s">'_lsprof.Profiler'</span> <span class="pl-s1">objects</span>}</pre></div>
<p dir="auto">and for numpy 1.16.4:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="         98807 function calls in 0.135 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000    0.135    0.135 &lt;string&gt;:1(&lt;module&gt;)
        1    0.004    0.004    0.135    0.135 numpy_benchmark.py:113(mean_benchmark)
     7600    0.004    0.000    0.131    0.000 numpy_benchmark.py:9(mean_test)
     7600    0.010    0.000    0.127    0.000 fromnumeric.py:3014(mean)
     7600    0.062    0.000    0.117    0.000 _methods.py:58(_mean)
     7600    0.020    0.000    0.020    0.000 {method 'reduce' of 'numpy.ufunc' objects}
     7600    0.016    0.000    0.020    0.000 _methods.py:48(_count_reduce_items)
     7600    0.005    0.000    0.006    0.000 numeric.py:541(asanyarray)
    15200    0.005    0.000    0.005    0.000 {issubclass}
    15200    0.004    0.000    0.004    0.000 {isinstance}
     7601    0.003    0.000    0.003    0.000 {range}
     7600    0.002    0.000    0.002    0.000 {hasattr}
     7600    0.002    0.000    0.002    0.000 {numpy.array}
        1    0.000    0.000    0.000    0.000 numeric.py:175(ones)
        1    0.000    0.000    0.000    0.000 {numpy.copyto}
        1    0.000    0.000    0.000    0.000 {numpy.empty}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}"><pre class="notranslate">         <span class="pl-c1">98807</span> <span class="pl-s1">function</span> <span class="pl-s1">calls</span> <span class="pl-c1">in</span> <span class="pl-c1">0.135</span> <span class="pl-s1">seconds</span>

   <span class="pl-v">Ordered</span> <span class="pl-s1">by</span>: <span class="pl-s1">cumulative</span> <span class="pl-s1">time</span>

   <span class="pl-s1">ncalls</span>  <span class="pl-s1">tottime</span>  <span class="pl-s1">percall</span>  <span class="pl-s1">cumtime</span>  <span class="pl-s1">percall</span> <span class="pl-s1">filename</span>:<span class="pl-en">lineno</span>(<span class="pl-s1">function</span>)
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.135</span>    <span class="pl-c1">0.135</span> <span class="pl-c1">&lt;</span><span class="pl-s1">string</span><span class="pl-c1">&gt;</span>:<span class="pl-c1">1</span>(<span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>)
        <span class="pl-c1">1</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.135</span>    <span class="pl-c1">0.135</span> <span class="pl-s1">numpy_benchmark</span>.<span class="pl-s1">py</span>:<span class="pl-c1">113</span>(<span class="pl-s1">mean_benchmark</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.131</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">numpy_benchmark</span>.<span class="pl-s1">py</span>:<span class="pl-c1">9</span>(<span class="pl-s1">mean_test</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.010</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.127</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">fromnumeric</span>.<span class="pl-s1">py</span>:<span class="pl-c1">3014</span>(<span class="pl-s1">mean</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.062</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.117</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">_methods</span>.<span class="pl-s1">py</span>:<span class="pl-c1">58</span>(<span class="pl-s1">_mean</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.020</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.020</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">method</span> <span class="pl-s">'reduce'</span> <span class="pl-s1">of</span> <span class="pl-s">'numpy.ufunc'</span> <span class="pl-s1">objects</span>}
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.016</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.020</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">_methods</span>.<span class="pl-s1">py</span>:<span class="pl-c1">48</span>(<span class="pl-s1">_count_reduce_items</span>)
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.005</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.006</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">numeric</span>.<span class="pl-s1">py</span>:<span class="pl-c1">541</span>(<span class="pl-s1">asanyarray</span>)
    <span class="pl-c1">15200</span>    <span class="pl-c1">0.005</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.005</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">issubclass</span>}
    <span class="pl-c1">15200</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.004</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">isinstance</span>}
     <span class="pl-c1">7601</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.003</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">range</span>}
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">hasattr</span>}
     <span class="pl-c1">7600</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.002</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">numpy</span>.<span class="pl-s1">array</span>}
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> <span class="pl-s1">numeric</span>.<span class="pl-s1">py</span>:<span class="pl-c1">175</span>(<span class="pl-s1">ones</span>)
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">numpy</span>.<span class="pl-s1">copyto</span>}
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">numpy</span>.<span class="pl-s1">empty</span>}
        <span class="pl-c1">1</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span>    <span class="pl-c1">0.000</span> {<span class="pl-s1">method</span> <span class="pl-s">'disable'</span> <span class="pl-s1">of</span> <span class="pl-s">'_lsprof.Profiler'</span> <span class="pl-s1">objects</span>}</pre></div>
<p dir="auto">The numpy/python version information printouts are:<br>
For numpy 1.11.0:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="('1.11.0', '2.7.12 (default, Nov 12 2018, 14:36:49) \n[GCC 5.4.0 20160609]')"><pre lang="&gt;&gt;&gt;" class="notranslate"><code class="notranslate">('1.11.0', '2.7.12 (default, Nov 12 2018, 14:36:49) \n[GCC 5.4.0 20160609]')
</code></pre></div>
<p dir="auto">For numpy 1.16.4:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="('1.16.4', '2.7.12 (default, Nov 12 2018, 14:36:49) \n[GCC 5.4.0 20160609]')"><pre lang="&gt;&gt;&gt;" class="notranslate"><code class="notranslate">('1.16.4', '2.7.12 (default, Nov 12 2018, 14:36:49) \n[GCC 5.4.0 20160609]')
</code></pre></div>
<p dir="auto">I'm using pip install to install these different versions of numpy, and I'm running these tests on a machine with Ubuntu 16.04 with a i7-8650U CPU.</p>
<p dir="auto">It's not a huge difference, but it seems to be consistent and also seems to affect other numpy operations as well. I am seeing a ~5 % decrease in run time for my overall code. I've also tested a few different versions of numpy (1.12.1, 1.13.3, 1.14.5, 1.15.4), and all seem to be slower than 1.11.0.</p>