[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 [1]: m= 1e5
In [2]: n= 1e2
In [3]: o= ones(n)
In [4]: M= randn(m, n)
In [5]: timeit M.sum(1)
100 loops, best of 3: 19.2 ms per loop
In [6]: timeit dot(M, o)
100 loops, best of 3: 15 ms per loop
In [7]: m= 1e2
In [8]: n= 1e5
In [9]: o= ones(n)
In [10]: M= randn(m, n)
In [11]: timeit M.sum(1)
100 loops, best of 3: 17.4 ms per loop
In [12]: 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>
More information about the NumPy-Discussion
mailing list