[SciPy-User] why is my scipy slow?

John jmjatkins@gmail....
Thu Jan 31 21:39:55 CST 2013


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





More information about the SciPy-User mailing list