[Numpy-discussion] Benchmak on record arrays
Charles R Harris
charlesr.harris at gmail.com
Wed May 27 12:01:51 EDT 2009
On Wed, May 27, 2009 at 9:31 AM, Nicolas Rougier
<Nicolas.Rougier at loria.fr>wrote:
>
> Hi,
>
> I've written a very simple benchmark on recarrays:
>
> import numpy, time
>
> Z = numpy.zeros((100,100), dtype=numpy.float64)
> Z_fast = numpy.zeros((100,100), dtype=[('x',numpy.float64),
> ('y',numpy.int32)])
> Z_slow = numpy.zeros((100,100), dtype=[('x',numpy.float64),
> ('y',numpy.bool)])
>
> t = time.clock()
> for i in range(10000): Z*Z
> print time.clock()-t
>
> t = time.clock()
> for i in range(10000): Z_fast['x']*Z_fast['x']
> print time.clock()-t
>
> t = time.clock()
> for i in range(10000): Z_slow['x']*Z_slow['x']
> print time.clock()-t
>
>
> And got the following results:
> 0.23
> 0.37
> 3.96
>
> Am I right in thinking that the last case is quite slow because of some
> memory misalignment between float64 and bool or is there some machinery
> behind that makes things slow in this case ?
Probably. Record arrays are stored like packed c structures and need to be
unpacked by copying the bytes to aligned data types.
> Should this be mentioned somewhere in the recarray documentation ?
A note would be appropriate, yes. You should be able to do that, do you have
edit permissions for the documentation?
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090527/65ae8a0a/attachment.html>
More information about the NumPy-Discussion
mailing list