[Numpy-discussion] speed of append_fields() in numpy.lib.recfunctions vs matplotlib.mlab
cgraves
christoph.graves@gmail....
Fri Apr 6 17:50:17 CDT 2012
It seems that the speed of append_fields() in numpy.lib.recfunctions is much
slower than rec_append_fields() in matplotlib.mlab. See the following code:
import numpy as np
import matplotlib.mlab as mlab
import numpy.lib.recfunctions as nprf
import time
# Set up recarray
nr_pts = 1E6
dt = np.dtype([('x', float), ('y', float)])
data = np.zeros(nr_pts, dtype=dt)
data = data.view(np.recarray)
data.x = np.linspace(0,5,nr_pts)
data.y = np.linspace(5,10,nr_pts)
z = np.linspace(20,15,nr_pts)
# Test mlab
last_time_clock = time.clock()
data_mlab = mlab.rec_append_fields(data, ['z'], [z])
time_taken = time.clock() - last_time_clock
print 'mlab took %i milliseconds.' % (time_taken*1000)
# Test nprf
last_time_clock = time.clock()
data_nprf = nprf.append_fields(data, ['z'], [z], usemask=False,
asrecarray=True)
time_taken = time.clock() - last_time_clock
print 'nprf took %i milliseconds.' % (time_taken*1000)
On this computer, the output is (+/- 10 ms):
mlab took 49 milliseconds.
nprf took 440 milliseconds.
Does anyone know why the numpy.lib.recfunctions version is so much slower? I
thought these were a port from matplotlib.mlab.
Changing to usemask=True has an effect on the time of the nprf way, making
it vary 330-480 ms (still much slower).
I'm using numpy 1.5.1.
Best,
Chris
--
View this message in context: http://old.nabble.com/speed-of-append_fields%28%29-in-numpy.lib.recfunctions-vs-matplotlib.mlab-tp33646038p33646038.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.
More information about the NumPy-Discussion
mailing list