[Numpy-discussion] Interesting timing results
Travis Oliphant
oliphant.travis at ieee.org
Tue Jan 17 15:32:03 CST 2006
Sasha wrote:
>>python -m timeit -s "x=bool(0)" "x or x"
>>
>>
>10000000 loops, best of 3: 0.111 usec per loop
>
>
>>python -m timeit -s "from numpy import bool_, logical_or as or_; x=bool_(0)" "or_(x, x)"
>>
>>
>100000 loops, best of 3: 3.25 usec per loop
>
>Numpy is 32x slower than python -- not very good.
>
>
This is a known fact. Currently all array scalar math goes through the
entire ufunc machinery. This is clearly sub-optimal. It is the reason
for the scalarmath module that I've started in the src directory.
Eventually, we should be able to have scalar math as fast as Python
scalars.
Anybody wanting to help out. This is a good place. One issue is how to
handle scalar math division-by-zero, and overflow errors. Ideally these
should be handled the same way that ufuncs do. But, this will
necessarily cause some slow-down to look up the local and-or
module-level attribute that can alter the behavior.
-Travis
>Interestingly,
>
>
>
>>python -m timeit -s "from numpy import bool_; x=bool_(0)" "x or x"
>>
>>
>1000000 loops, best of 3: 0.388 usec per loop
>
>
Again, not too surprising given that logical_or goes through the ufunc
machinery...
-Travis
More information about the Numpy-discussion
mailing list