[Numpy-discussion] About speed vs math...

David Cournapeau cournape@gmail....
Mon Jun 3 01:33:23 CDT 2013


On Mon, Jun 3, 2013 at 6:29 AM, Jerome Kieffer <Jerome.Kieffer@esrf.fr> wrote:
> Hello,
>
> I am giving some introduction tutorials to numpy and we notices a big
> difference in speed between nuumpy and math for trigonometric
> operations:
>
> In [3]: %timeit numpy.sin(1)
> 100000 loops, best of 3: 2.27 us per loop
>
> In [4]: %timeit math.sin(1)
> 10000000 loops, best of 3: 92.3 ns per loop
>
> While not surprising, I did not expect numpy to be so much slower (25x)...

It is a known limitation of numpy scalars. As soon as you use array
that are not tiny, the speed difference disappears and then favors
numpy arrays (around 50 on my own machine, but that's platform
specific).

David


More information about the NumPy-Discussion mailing list