[SciPy-user] More on speed comparisons

Ivo Maljevic ivo.maljevic@gmail....
Mon Jun 16 10:13:48 CDT 2008


Aside from good speed with SciPy (I feel embarrassed that I made that 'sum'
mistake), I am impressed with the speed of reaction of you guys (David,
Gael, Anne, Matthieu, Robert). These are the names I have picked up so far
to be the most frequent.

Geal, you are working the internals of the SciPy and therefore you might be
interested in timing for individual loop execution time, but for me the most
relevant time is how long does it take to execute simulation from the moment
I press return to the moment it is all done. Typically, I use:

time command (e.g., time python ./rand_test_2.py). While you may find this
methodology incorrect,
I do the same with fortran and C code (time ./rand_test_c or time
./rand_test_f).

Some of my matlab simulation run for more than one hour and I use tic/toc
there.

Ivo

2008/6/16 Gael Varoquaux <gael.varoquaux@normalesup.org>:

> On Mon, Jun 16, 2008 at 10:45:10AM -0400, Ivo Maljevic wrote:
> >    I knew I should have refrained from sending my "findings". Especially
> >    because I was quick to
> >    jump to conclusions :(
>
> >    It turns out SciPy is as fast as octave when written in a vector form.
> The
> >    correct version of
> >    the array form of the script is (it was not using proper version of
> the
> >    sum function):
>
> Indeed. I am also curious to know how you measure timings. The proper way
> of mesuring timings (ie measuring CPU time, and not wall time) is using
> the timeit module. You can either use the timeit shell command, or the
> timeit magic, in ipython. Here are the results I get:
>
> ##########################################################################
> # rand_test_1.py
> from random import random
> from math import sqrt, sin
>
> def do_python():
>     N = 1000000
>
>    mean = 0
>    var  = 0
>
>    for i in range(N):
>        x = random()
>        x = 3.14*sqrt(x)
>        x = sin(x)
>        mean += x
>        var += x**2
>
>    mean = mean/N
>    var  = var/N - mean**2
>    print 'Mean=%g, var=%g' % (mean, var)
>
> # rand_test_2.py
>
> def do_numpy():
>    import numpy as np
>
>    N = 1000000
>
>    x = np.random.rand(N)
>    x = 3.14*np.sqrt(x)
>    x = np.sin(x)
>
>    mean = x.mean()
>    var  = np.sum(x**2)/N - mean**2
>
>    print 'Mean=%g, var=%g' % (mean, var)
> ##########################################################################
>
> And in ipython:
>
>    In [1]: %run test.py
>
>    In [2]: %timeit do_python()
>    [... snip ]
>    10 loops, best of 3: 1.18 s per loop
>
>    In [3]: %timeit do_numpy()
>    10 loops, best of 3: 147 ms per loop
>
> This is significantly different from your timings. The numbers do not
> mean the same thing, but I trust these one more, and would try to use CPU
> time only for comparisons between different approachs.
>
> My 2 cents.
>
> Gaël
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080616/882af886/attachment.html 


More information about the SciPy-user mailing list