<h3 dir="auto">Reproducing code example:</h3>

<p dir="auto">Write a <code class="notranslate">demo.py</code>:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from __future__ import print_function

import time

import numpy as np
import six

if six.PY3:
    timer_func = time.process_time
else:
    timer_func = time.clock

n = 1000

start = timer_func()
precise = 2
for i in range(n):
    np.round(np.array(range(i)), precise)
end = timer_func()
print(end-start)
"><pre class="notranslate"><span class="pl-k">from</span> __future__ <span class="pl-k">import</span> <span class="pl-s1">print_function</span>

<span class="pl-k">import</span> <span class="pl-s1">time</span>

<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">six</span>

<span class="pl-k">if</span> <span class="pl-s1">six</span>.<span class="pl-v">PY3</span>:
    <span class="pl-s1">timer_func</span> <span class="pl-c1">=</span> <span class="pl-s1">time</span>.<span class="pl-s1">process_time</span>
<span class="pl-k">else</span>:
    <span class="pl-s1">timer_func</span> <span class="pl-c1">=</span> <span class="pl-s1">time</span>.<span class="pl-s1">clock</span>

<span class="pl-s1">n</span> <span class="pl-c1">=</span> <span class="pl-c1">1000</span>

<span class="pl-s1">start</span> <span class="pl-c1">=</span> <span class="pl-en">timer_func</span>()
<span class="pl-s1">precise</span> <span class="pl-c1">=</span> <span class="pl-c1">2</span>
<span class="pl-k">for</span> <span class="pl-s1">i</span> <span class="pl-c1">in</span> <span class="pl-en">range</span>(<span class="pl-s1">n</span>):
    <span class="pl-s1">np</span>.<span class="pl-en">round</span>(<span class="pl-s1">np</span>.<span class="pl-en">array</span>(<span class="pl-en">range</span>(<span class="pl-s1">i</span>)), <span class="pl-s1">precise</span>)
<span class="pl-s1">end</span> <span class="pl-c1">=</span> <span class="pl-en">timer_func</span>()
<span class="pl-en">print</span>(<span class="pl-s1">end</span><span class="pl-c1">-</span><span class="pl-s1">start</span>)</pre></div>
<p dir="auto">Then run it like this:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# Py2
python -m cProfile -o demo-py2.prof demo.py

# Py3
python -m cProfile -o demo-py3.prof demo.py"><pre class="notranslate"><span class="pl-c"><span class="pl-c">#</span> Py2</span>
python -m cProfile -o demo-py2.prof demo.py

<span class="pl-c"><span class="pl-c">#</span> Py3</span>
python -m cProfile -o demo-py3.prof demo.py</pre></div>
<p dir="auto">And view the profiles with snakeviz <code class="notranslate">pip install snakeviz</code>:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# Under Python2's virtual env:
snakeviz demo-py2.prof

# Under Python3's virtual env:
snakeviz demo-py2.prof"><pre class="notranslate"><span class="pl-c"><span class="pl-c">#</span> Under Python2's virtual env:</span>
snakeviz demo-py2.prof

<span class="pl-c"><span class="pl-c">#</span> Under Python3's virtual env:</span>
snakeviz demo-py2.prof</pre></div>
<p dir="auto">Get web page:</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/13536789/63755276-e7e4a500-c8e8-11e9-9ca0-0411d3e986d1.png"><img src="https://user-images.githubusercontent.com/13536789/63755276-e7e4a500-c8e8-11e9-9ca0-0411d3e986d1.png" alt="NumPy-Python2" style="max-width: 100%;"></a></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/13536789/63755281-ea46ff00-c8e8-11e9-9481-5a3575e39be7.png"><img src="https://user-images.githubusercontent.com/13536789/63755281-ea46ff00-c8e8-11e9-9481-5a3575e39be7.png" alt="NumPy-Python3" style="max-width: 100%;"></a></p>
<p dir="auto">And the purple part it time cost on loading packages.</p>

<h3 dir="auto">Error message:</h3>


<h3 dir="auto">Numpy/Python version information:</h3>

<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import sys, numpy; print(numpy.__version__, sys.version)
1.16.4 2.7.16 (default, Apr 12 2019, 15:32:40)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.3)]"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">sys</span>, <span class="pl-s1">numpy</span>; <span class="pl-en">print</span>(<span class="pl-s1">numpy</span>.<span class="pl-s1">__version__</span>, <span class="pl-s1">sys</span>.<span class="pl-s1">version</span>)
<span class="pl-c1">1.16</span>.<span class="pl-c1">4</span> <span class="pl-c1">2.7</span>.<span class="pl-c1">16</span> (<span class="pl-s1">default</span>, <span class="pl-v">Apr</span> <span class="pl-c1">12</span> <span class="pl-c1">2019</span>, <span class="pl-c1">15</span>:<span class="pl-c1">32</span>:<span class="pl-c1">40</span>)
[<span class="pl-v">GCC</span> <span class="pl-c1">4.2</span><span class="pl-c1">.1</span> <span class="pl-v">Compatible</span> <span class="pl-v">Apple</span> <span class="pl-v">LLVM</span> <span class="pl-c1">10.0</span><span class="pl-c1">.1</span> (<span class="pl-s1">clang</span><span class="pl-c1">-</span><span class="pl-c1">1001.0</span>.<span class="pl-c1">46.3</span>)]</pre></div>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import sys, numpy; print(numpy.__version__, sys.version)
1.16.4 3.7.4 (default, Jul  9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)]"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">sys</span>, <span class="pl-s1">numpy</span>; <span class="pl-en">print</span>(<span class="pl-s1">numpy</span>.<span class="pl-s1">__version__</span>, <span class="pl-s1">sys</span>.<span class="pl-s1">version</span>)
<span class="pl-c1">1.16</span>.<span class="pl-c1">4</span> <span class="pl-c1">3.7</span>.<span class="pl-c1">4</span> (<span class="pl-s1">default</span>, <span class="pl-v">Jul</span>  <span class="pl-c1">9</span> <span class="pl-c1">2019</span>, <span class="pl-c1">18</span>:<span class="pl-c1">13</span>:<span class="pl-c1">23</span>)
[<span class="pl-v">Clang</span> <span class="pl-c1">10.0</span><span class="pl-c1">.1</span> (<span class="pl-s1">clang</span><span class="pl-c1">-</span><span class="pl-c1">1001.0</span>.<span class="pl-c1">46.4</span>)]</pre></div>
<p dir="auto">I just ran the brand new <code class="notranslate">python -X importtime -c "import numpy"</code>. Turns out that <code class="notranslate">numpy.testing</code> takes rougly 29 % (23 ms) of the total import time (80 ms), most of which (62 %, 14 ms) is the <code class="notranslate">unittest</code> module (no <code class="notranslate">nose</code> in my environment).  In view of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="312143807" data-permission-text="Title is private" data-url="https://github.com/numpy/numpy/issues/10856" data-hovercard-type="issue" data-hovercard-url="/numpy/numpy/issues/10856/hovercard" href="https://github.com/numpy/numpy/issues/10856">#10856</a>, this is only going to get worse -- <code class="notranslate">pytest</code> weighs in with about 35 ms on my machine.</p>
<p dir="auto">So there's an opportunity for an easy win in import time by making the import of <code class="notranslate">numpy.testing</code> lazy. That is, <em>if</em> such a change doesn't cause huge amounts of downstream breakage.<br>
Alternatively, the main culprits could be imported lazily, with a much smaller downstream impact (likely none).</p>