[SciPy-User] numexpr.evaluate slower than eval, why?

Gerrit Holl gerrit.holl at ltu.se
Mon Nov 1 15:24:51 EDT 2010


Hi,

(since I couldn't find any numexpr mailing-list, I ask the question here)

I am working with pytables and numexpr. I use pytables' .where()
method to select fields from my data. Sometimes I can't do that and I
need to select them "by hand", but to keep the interface constant and
avoid the need to parse things myself, I evaluate the same strings to
sub-select fields from my data. To my surprise, numexpr.evaluate is
about two times slower than eval. Why?

In [130]: %timeit numexpr.evaluate('MEAN>1000', recs)
10000 loops, best of 3: 117 us per loop

In [131]: %timeit eval('MEAN>1000', {}, {'MEAN': recs['MEAN']})
10000 loops, best of 3: 55.4 us per loop

In [132]: %timeit recs['MEAN']>1000
10000 loops, best of 3: 42.1 us per loop

(on a side-note: what is python/evals definition of a mapping? numexpr
evaluates recs (a numpy.recarray) as a mapping, but eval does not)

regards,
Gerrit Holl.



More information about the SciPy-User mailing list