[SciPy-User] why is my scipy slow?

Warren Weckesser warren.weckesser@gmail....
Thu Jan 31 21:55:01 CST 2013


On Thu, Jan 31, 2013 at 10:39 PM, John <jmjatkins@gmail.com> wrote:

> Hello,
>
> I've been using scipy for a few weeks now and for the most part am
> thoughily
> enjoying it! However I have been porting code from matlab and have been
> surprissed by how much slower it is runnning under python. So much so that
> I
> suspect I must be doing something wrong. Below is an example. In matlab the
> doSomething() function takes 6.4ms. In python it taks 78ms, more than 10x
> slower. Does this seem right? Or am I missing something? I installed the
> Enthough distribution for Windows. Any advise much appreaciated!
>
> First in python:
>
> import time
> import scipy.signal
>
> def speedTest():
>     rep = 1000
>     tt = time.time()
>     for i in range(rep):
>         doSomething()
>     print (time.time() - tt) / rep
>
> def doSomething():
>     lp = scipy.signal.firwin(16, 0.5);
>     data = scipy.rand(100000)
>     data = scipy.signal.convolve(data, lp)
>
> if __name__ == '__main__':
>     speedTest()
>
>
>
> Now in matlab:
>
> function matlabSpeedTest()
>     rep = 1000;
>     tStart=tic;
>     for j=1:rep
>         doSomething();
>     end
>     tElapsed=toc(tStart)/rep;
>     str = sprintf('time %s', tElapsed);
>     disp(str);
> end
>
> function data = doSomething()
>     lp = fir1(16,0.5);
>     data = rand(100000, 1, 'double');
>     data = conv(lp, data);
> end
>
>
>
There are several methods you can use to apply a FIR filter to a signal;
scipy.signal.convolve is actually one of the slowest.  See
http://www.scipy.org/Cookbook/ApplyFIRFilter for a comparison of the
methods.

Warren


>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130131/57ddeae1/attachment-0001.html 


More information about the SciPy-User mailing list