<br><br><div class="gmail_quote">On Wed, May 27, 2009 at 9:31 AM, Nicolas Rougier <span dir="ltr"><<a href="mailto:Nicolas.Rougier@loria.fr">Nicolas.Rougier@loria.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi,<br>
<br>
I've written a very simple benchmark on recarrays:<br>
<br>
import numpy, time<br>
<br>
Z = numpy.zeros((100,100), dtype=numpy.float64)<br>
Z_fast = numpy.zeros((100,100), dtype=[('x',numpy.float64),<br>
('y',numpy.int32)])<br>
Z_slow = numpy.zeros((100,100), dtype=[('x',numpy.float64),<br>
('y',numpy.bool)])<br>
<br>
t = time.clock()<br>
for i in range(10000): Z*Z<br>
print time.clock()-t<br>
<br>
t = time.clock()<br>
for i in range(10000): Z_fast['x']*Z_fast['x']<br>
print time.clock()-t<br>
<br>
t = time.clock()<br>
for i in range(10000): Z_slow['x']*Z_slow['x']<br>
print time.clock()-t<br>
<br>
<br>
And got the following results:<br>
0.23<br>
0.37<br>
3.96<br>
<br>
Am I right in thinking that the last case is quite slow because of some<br>
memory misalignment between float64 and bool or is there some machinery<br>
behind that makes things slow in this case ?</blockquote><div><br>Probably. Record arrays are stored like packed c structures and need to be unpacked by copying the bytes to aligned data types.<br> <br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Should this be mentioned somewhere in the recarray documentation ?</blockquote><div><br>A note would be appropriate, yes. You should be able to do that, do you have edit permissions for the documentation?<br><br>Chuck<br>
</div><br></div><br>