<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-07-06 18:04 GMT+02:00 Jaime Fernández del Río <span dir="ltr"><<a href="mailto:jaime.frio@gmail.com" target="_blank">jaime.frio@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5">On Mon, Jul 6, 2015 at 10:18 AM, Francesc Alted <span dir="ltr"><<a href="mailto:faltet@gmail.com" target="_blank">faltet@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I have stumbled into this:</div><div><br></div><div><div><div>In [62]: sa = np.fromiter(((i,i) for i in range(1000*1000)), dtype=[('f0', np.int64), ('f1', np.int32)])</div><div><br></div><div>In [63]: %timeit sa['f0'].sum()</div><div>100 loops, best of 3: 4.52 ms per loop</div><div><br></div><div>In [64]: sa = np.fromiter(((i,i) for i in range(1000*1000)), dtype=[('f0', np.int64), ('f1', np.int64)])</div><div><br></div><div>In [65]: %timeit sa['f0'].sum()</div><div>1000 loops, best of 3: 896 µs per loop</div><div><br></div></div><div>The first structured array is made of 12-byte records, while the second is made by 16-byte records, but the latter performs 5x faster.  Also, using an structured array that is made of 8-byte records is the fastest (expected):</div><div><br></div><div><div>In [66]: sa = np.fromiter(((i,) for i in range(1000*1000)), dtype=[('f0', np.int64)])</div><div><br></div><div>In [67]: %timeit sa['f0'].sum()</div><div>1000 loops, best of 3: 567 µs per loop</div><div><br></div><div>Now, my laptop has a Ivy Bridge processor (i5-3380M) that should perform quite well on unaligned data:<br></div></div><div><br></div><div><a href="http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/" target="_blank">http://lemire.me/blog/archives/2012/05/31/data-alignment-for-speed-myth-or-reality/</a><br></div><div><br></div><div>So, if 4 years-old Intel architectures do not have a penalty for unaligned access, why I am seeing that in NumPy?  That strikes like a quite strange thing to me.</div></div></div></blockquote><div><br></div></div></div><div>I believe that the way numpy is setup, it never does unaligned access, regardless of the platform, in case it gets run on one that would go up in flames if you tried to. So my guess would be that you are seeing chunked copies into a buffer, as opposed to bulk copying or no copying at all, and that would explain your timing differences. But Julian or Sebastian can probably give you a more informed answer.</div></div></div></div></blockquote><div><br></div><div>Yes, my guess is that you are right.  I suppose that it is possible to improve the numpy codebase to accelerate this particular access pattern on Intel platforms, but provided that structured arrays are not that used (pandas is probably leading this use case by far, and as far as I know, they are not using structured arrays internally in DataFrames), then maybe it is not worth to worry about this too much.</div><div><br></div><div>Thanks anyway,</div><div>Francesc</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Jaime</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><div dir="ltr"><div><div><br></div><div>Thanks,</div><div>Francesc</div><span><font color="#888888"><div><br></div>-- <br><div>Francesc Alted</div>
</font></span></div></div>
<br></span>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org" target="_blank">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><span class=""><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>(\__/)<br>( O.o)<br>( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.</div>
</font></span></div></div>
<br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Francesc Alted</div>
</div></div>