[SciPy-User] Speed-up simple function

Francesc Alted faltet at pytables.org
Mon Jan 10 11:52:33 EST 2011


A Monday 10 January 2011 16:47:44 g.plantageneto at runbox.com escrigué:
> > This looks terribly over complicated. What are you trying to do and
> > where is the polynomial?
> 
> I see, sorry, I'll try to put it more clearly. My computation is
> something like this: for each time step, I compute the value of some
> polynomial on all array elements, then I average the results to
> obtain a single number:
[clip]

As others have said, Cython is good option.  Perhaps even easier would 
be Numexpr, that let's you get nice speed-ups on complex expressions, 
and as a plus, it lets you use any number of cores that your machine 
has.

I've made a small demo (attached) on how Numexpr works based on your 
polynomial.  Here are my results of running it on a 6-core machine:

Computing with NumPy with 10^5 elements:
time spent: 0.0169
Computing with Numexpr with 10^5 elements:
time spent for 1 threads: 0.0052 speed-up: 3.22
time spent for 2 threads: 0.0028 speed-up: 6.11
time spent for 3 threads: 0.0022 speed-up: 7.82
time spent for 4 threads: 0.0016 speed-up: 10.26
time spent for 5 threads: 0.0014 speed-up: 12.31
time spent for 6 threads: 0.0013 speed-up: 13.35

Cheers,

-- 
Francesc Alted
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 1961 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110110/41776a22/attachment.py>


More information about the SciPy-User mailing list