[SciPy-user] More on speed comparisons

David Cournapeau david@ar.media.kyoto-u.ac...
Mon Jun 16 09:46:48 CDT 2008


Ivo Maljevic wrote:
> However, I wanted to see if SciPy would be good enough speedwise to 
> completely replace Matlab. An, at least for the type of processing I 
> do, it comes nowhere near it.

Note that random number generator greatly vary across languages and 
implementations.

> The numbers are rounded a little bit, but they are in that range. I 
> see two problems here:
>
> 1. SciPy is very slow, even when compared to Octave 3.0
> 2. It is only sligtly faster than Python with a for loop.

That's really surprising. Also, I quickly checked: random is as fast 
under scipy as under matlab. The problem is not random (which takes less 
than 10 % of the running time; as always, use profiling :) ).

And I found your problem: sum. You are not using numpy sum, but python 
sum, which is extremely slow (it has to convert the array to a sequence 
first I think, which means it may well be slower than looping :) ).

Here is my version:

from numpy import random, sin, sqrt, mean, var

def compute():
    N = 1000000
  
    x = random.rand(N)
    x = 3.14*sqrt(x)
    x = sin(x)
                                                                                         

    m = mean(x)
    v = var(x)
       
    print 'Mean=', m, ', var=', 
v                                                       
       
if __name__ == 
'__main__':                                                              
    compute()

This is roughly ten times faster than your scipy version on my computer. 
Which means we are pretty close to C performances :)

cheers,

David


More information about the SciPy-user mailing list