Whilst playing around with this question I noticed something I couldn't explain regarding the relative performance of np.log2
, np.log
and np.log10
:
In [1]: %%timeit x = np.random.rand(100000)
....: np.log2(x)
....:
1000 loops, best of 3: 1.31 ms per loop
In [2]: %%timeit x = np.random.rand(100000)
np.log(x)
....:
100 loops, best of 3: 3.64 ms per loop
In [3]: %%timeit x = np.random.rand(100000)
np.log10(x)
....:
100 loops, best of 3: 3.93 ms per loop
np.log2
is about 3x faster than np.log
and np.log10
. Perhaps even more counter-intuitively, np.log1p(x)
, which computes ln(x + 1), is on par with np.log2
:
In [4]: %%timeit x = np.random.rand(100000)
np.log1p(x)
....:
1000 loops, best of 3: 1.46 ms per loop
I obtained almost identical timings in numpy v1.10.1 and v1.8.2.
Is there an intuitive explanation for these discrepancies in runtime performance?