Numpy log slow for numbers close to 1?
<p>Look at the following piece of code:</p>

<pre><code>import numpy as np
import timeit

print('close', timeit.Timer(lambda: np.log(0.99999999999999978)).timeit())
print('not close', timeit.Timer(lambda: np.log(0.99)).timeit()))
</code></pre>

<p>The output is:</p>

<pre><code>close 4.462684076999722
not close 0.6319260000018403
</code></pre>

<p>How come such big (orders of magnitude) difference in running time? Am I missing something?</p>

<p>EDIT:</p>

<p>More preceisly we see the slowdown for values as small as:
<code>1 - np.finfo(np.float).eps</code>
but not for values
<code>1 - np.finfo(np.float).eps * 10</code>.</p>

<p>My machine <code>Python 3.5.2 |Anaconda 4.1.1 (64-bit)</code> with <code>numpy 1.11.1</code>. </p>

<p>This has been so far reproduced on 3 other machines from my side (2 Python 3.4 Anaconda installations, 1 Python 2.7 default Ubuntu installation).</p>

<p>Some other users could also reproduce it, while others could not. See comments.</p>

<p>EDIT 2:</p>

<p>Possibly only reproducible on Linux systems. So far, not reproducible on Windows systems.</p>

<p>At the time of writing, most chipsets evaluate <code>log</code> using a Taylor series coupled with a table of specific pre-computed values.</p>

<p>With the Taylor series, a number closer to 1 is slower to <em>converge</em> than a number further away from 1. That could go some way to explaining the difference in execution time observed here.</p>

<p><code>0.99</code> may also be closer to one of the tabulated values, which would also help.</p>

<p><strong>Or your observations may not even be statistically significant.</strong></p>

python numpy runtime