shunwang / numexpr

Automatically exported from code.google.com/p/numexpr
MIT License
0 stars 0 forks source link

Slow down compared to numpy #49

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In [1]: import numexpr as ne

In [2]: a =  np.random.random((3550, 8000))

In [3]: b = array(a[0])
\
In [4]: %timeit ne.evaluate('a - b')
1 loops, best of 3: 476 ms per loop

In [5]: %timeit a-b
1 loops, best of 3: 197 ms per loop

The expected output is that it would speed it up rathern than slow it down. 

Thanks for your help
     Wolfgang

Original issue reported on code.google.com by wkerzend...@gmail.com on 30 Mar 2011 at 5:27

GoogleCodeExporter commented 9 years ago
Your example triggers broadcasting of 'b', something which numexpr 
traditionally hasn't been good at. Using the newiter branch of numexpr, which 
takes advantage of features in NumPy 1.6 (which should have a release candidate 
soon), I get numexpr performing better:

In [4]: np.__version__
Out[4]: '2.0.0.dev-be364f7'

In [5]: ne.__version__
Out[5]: '2.0.dev290'

In [6]: a =  np.random.random((3550, 8000))

In [7]: b = array(a[0])

In [8]: %timeit ne.evaluate('a - b')
1 loops, best of 3: 214 ms per loop

In [9]: %timeit a-b
1 loops, best of 3: 308 ms per loop

In [10]: ne.set_num_threads(1)
Out[10]: 2

In [11]: %timeit ne.evaluate('a - b')
1 loops, best of 3: 291 ms per loop

With one thread, since the expression is just one operation, I would expect 
numexpr and numpy to perform the same, but it looks like numpy needs some more 
performance work. In general, more complex expressions are what numexpr will 
evaluate much faster than numpy.

Original comment by mwwi...@gmail.com on 27 Apr 2011 at 5:51

GoogleCodeExporter commented 9 years ago
The nditer branch has been merged into default, and I'm getting reasonable 
performance differences between numexpr and numpy. Can you confirm on your 
system?

Original comment by mwwi...@gmail.com on 30 Oct 2011 at 11:51