shunwang / numexpr

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

[PATCH] Loop optimization to gain ~15% performance #38

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Here is an *experimental* (ie incomplete and not heavily tested) patch which 
leads to a ~15% performance improvement here in a simple expression, at the 
expense of slightly uglier code.

Several comments:
- I'm compiling this with MingW 5.1.6, and other compilers might optimize the 
old version as well as what I did manually (I don't know).

- It is incomplete: so far, I didn't bother with VML code, and I might have 
broken reduce operations (possibly other stuff -- didn't run the test suite 
yet).

- It might be possible to do the same optimisation more cleanly.

I'm ready to try to make this a complete patch and maybe try to do it in a 
cleaner way, but before I spend any more time into it, I would like to know 
what you guys think about it and possibly try it on other compilers to see if 
it is worth the effort.

Here are my benchmarks:
without patch:

In [1]: import numpy as np
In [2]: import numexpr as ne
In [3]: a = np.arange(1e6)
In [4]: timeit ne.evaluate('0.25 * a ** 2 + 0.34 * a + 0.54')
100 loops, best of 3: 8.47 ms per loop

with patch:
In [4]: timeit ne.evaluate('0.25 * a ** 2 + 0.34 * a + 0.54')
100 loops, best of 3: 7.45 ms per loop

Original issue reported on code.google.com by gdemen...@gmail.com on 19 Nov 2010 at 9:55

Attachments:

GoogleCodeExporter commented 9 years ago
hmmm, please don't look at it/try it just yet :) I was so excited I didn't 
check if the results were even correct, and it turns out it computes garbage. I 
know why, so I'll fix this ASAP. I think and hope the speed will be the same 
after fixing that, but I'm not sure... Stay tuned...

Original comment by gdemen...@gmail.com on 19 Nov 2010 at 10:01

GoogleCodeExporter commented 9 years ago
For some reason, the correct version is slower than current numexpr. I guess 
this was too good to be true... It seems like my C optimization tricks from 15 
years ago don't work anymore... Please close this ticket (and bury it as deep 
as possible ;-)). Sorry for the spam.

Original comment by gdemen...@gmail.com on 19 Nov 2010 at 10:36

GoogleCodeExporter commented 9 years ago
Well, at least you experimented with the computing kernel, so you may say that 
you are kind of an 'expert' with numexpr now.  Remember that in order to get a 
good result you need to get wrong first (and not only once :-)

Original comment by fal...@gmail.com on 19 Nov 2010 at 10:58