[Numpy-discussion] Benchmak on record arrays

Nicolas Rougier Nicolas.Rougier@loria...
Wed May 27 14:21:37 CDT 2009



No, I don't have permission to edit.

Nicolas


On 27 May, 2009, at 18:01 , Charles R Harris wrote:

>
>
> On Wed, May 27, 2009 at 9:31 AM, Nicolas Rougier <Nicolas.Rougier@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
>
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090527/0128cae9/attachment.html 


More information about the Numpy-discussion mailing list