<br><br><div class="gmail_quote">On Thu, Feb 10, 2011 at 8:29 AM, eat <span dir="ltr"><<a href="mailto:e.antero.tammi@gmail.com">e.antero.tammi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>Hi,</div>
<div> </div>
<div>Observing following performance:</div>
<div><font face="courier new,monospace">In []: m= 1e5</font></div>
<div><font face="courier new,monospace">In []: n= 1e2</font></div>
<div><font face="courier new,monospace">In []: o= ones(n)</font></div>
<div><font face="courier new,monospace">In []: M= randn(m, n)</font></div>
<div><font face="courier new,monospace">In []: timeit M.sum(1)<br>10 loops, best of 3: 38.3 ms per loop</font></div>
<div><font face="courier new,monospace">In []: timeit dot(M, o)<br>10 loops, best of 3: 21.1 ms per loop</font></div>
<div><font face="courier new,monospace"></font> </div>
<div><font face="courier new,monospace">In []: m= 1e2</font></div>
<div><font face="courier new,monospace">In []: n= 1e5</font></div>
<div><font face="courier new,monospace">In []: o= ones(n)</font></div>
<div><font face="courier new,monospace">In []: M= randn(m, n)</font></div>
<div><font face="courier new,monospace">In []: timeit M.sum(1)<br>100 loops, best of 3: 18.3 ms per loop</font></div>
<div><font face="courier new,monospace">In []: timeit dot(M, o)<br>10 loops, best of 3: 21.2 ms per loop</font></div>
<div> </div>
<div>One would expect sum to outperform dot with a clear marginal. Does there exixts any 'tricks' to increase the performance of sum?</div>
<div> </div></blockquote><div><br>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<br>
<br><span style="font-family: courier new,monospace;">In [1]: m= 1e5</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [2]: n= 1e2</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [3]: o= ones(n)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [4]: M= randn(m, n)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [5]: timeit M.sum(1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">100 loops, best of 3: 19.2 ms per loop</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [6]: timeit dot(M, o)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">100 loops, best of 3: 15 ms per loop</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [7]: m= 1e2</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [8]: n= 1e5</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [9]: o= ones(n)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [10]: M= randn(m, n)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [11]: timeit M.sum(1)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">100 loops, best of 3: 17.4 ms per loop</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">In [12]: timeit dot(M, o)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">100 loops, best of 3: 14.2 ms per loop</span><br style="font-family: courier new,monospace;">
<br>Chuck    <br></div><br></div>