[Numpy-discussion] Benchmak on record arrays

Nicolas Rougier Nicolas.Rougier@loria...
Wed May 27 10:31:20 CDT 2009


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 ? Should this be mentioned
somewhere in the recarray documentation ?


Nicolas




More information about the Numpy-discussion mailing list