# [Numpy-discussion] odd performance of sum?

Charles R Harris charlesr.harris at gmail.com
Thu Feb 10 12:10:23 EST 2011

```On Thu, Feb 10, 2011 at 8:29 AM, eat <e.antero.tammi at gmail.com> wrote:

> Hi,
>
> Observing following performance:
> In []: m= 1e5
> In []: n= 1e2
> In []: o= ones(n)
> In []: M= randn(m, n)
> In []: timeit M.sum(1)
> 10 loops, best of 3: 38.3 ms per loop
> In []: timeit dot(M, o)
> 10 loops, best of 3: 21.1 ms per loop
>
> In []: m= 1e2
> In []: n= 1e5
> In []: o= ones(n)
> In []: M= randn(m, n)
> In []: timeit M.sum(1)
> 100 loops, best of 3: 18.3 ms per loop
> In []: timeit dot(M, o)
> 10 loops, best of 3: 21.2 ms per loop
>
> One would expect sum to outperform dot with a clear marginal. Does there
> exixts any 'tricks' to increase the performance of sum?
>
>

I'm not surprised, much depends on the version of ATLAS or MKL you are
linked to. If you aren't linked to either and just using numpy's version
then the results are a bit strange. With numpy development I get

In : m= 1e5

In : n= 1e2

In : o= ones(n)

In : M= randn(m, n)

In : timeit M.sum(1)
100 loops, best of 3: 19.2 ms per loop

In : timeit dot(M, o)
100 loops, best of 3: 15 ms per loop

In : m= 1e2

In : n= 1e5

In : o= ones(n)

In : M= randn(m, n)

In : timeit M.sum(1)
100 loops, best of 3: 17.4 ms per loop

In : timeit dot(M, o)
100 loops, best of 3: 14.2 ms per loop

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110210/4bf902c7/attachment.html>
```