[SciPy-user] NumPy vs. SciPy and other speed comparisons

Matthieu Brucher matthieu.brucher at gmail.com
Wed Jun 11 03:15:44 EDT 2008


Hi,

The difference in speed may be only due to the fact that the scipy modle has
much more functions than numpy's.

Import only what you need and try again.

Matthieu

2008/6/11 Ivo Maljevic <ivo.maljevic at gmail.com>:

> Hi,
> I am relatively new SciPy/NumPy user and I must say I like it. I don't know
> if this is something that is well known, but I run some simple tests,
> and I found out that, depending on whether one imports NumPy or SciPy,
> programs executes at quite different speeds. I'm guessing the problem has
> something to do with how it cycles through loops.
>
> My initial goal was to compare python scripts with octave/matlab ones, but
> then I noticed the speed difference between NumPy and SciPy.
>
> To cut the story short, here are results:
>
> Execution times in seconds, test 1:
>
> Python              Octave       Fortran            C
> ========================================================
> NumPy: 23.9         36.05        6.7                6.8
> SciPy: 44.5
>
>
> Execution times in seconds, test 2:
>
> Python              Octave       Fortran            C
> ========================================================
> NumPy: 9.4          5.5          6.7                6.8
> SciPy: 10.1
>
>
> Test cases 1 and 2 refer to different parameter values for the same scipts
> (test 1: FrameSize=100, test 2: FrameSize=10000).
>
> If anybody would like to experiment, I've copied the source code for the
> simple BPSK simulation that determines the raw bit error rate.
>
> To calculate erfc function with NumPy, I used a simple fotran funciton and
> comiled it into .so library:
>
> subroutine erfc(x,y)
>   real, intent(in)  :: x
>   real, intent(out) :: y
>   y = 1-erf(x)
>   end
>
> # Python script
>
> # For some reason, numpy is much faster than scipy, Try to comment out one
> or the other line
> #from numpy import *
> from scipy import *
> import erfc
>
> SNR_MIN   = -1
> SNR_MAX   = 10
> FrameSize = 100   # <-- change me for test 2
>
> Eb_No_dB  = arange(SNR_MIN,SNR_MAX+1)
>
> # signal vector
> s = ones(FrameSize)
> a = random.rand(FrameSize)
> a_i = where(a < 0.5)
> s[a_i] = -1
>
> for snr in Eb_No_dB:
>
>   No        = 10**(-snr/10.0)
>   Pe        = 0.5*erfc.erfc(sqrt(1.0/No))
>   nFrames   = ceil(200.0/FrameSize/Pe)
>   error_sum = 0
>
>   for frame in arange(nFrames):
>
>     # noise
>     #n = sqrt(No/2)*random.randn(FrameSize)
>     n = random.normal(scale=sqrt(No/2), size=FrameSize)
>     x = s + n
>
>     # detection
>     y = sign(x)
>
>     # error counting
>     err = where (y != s)
>     error_sum += len(err[0])
>
>   print 'Eb_No_dB=%2d, BER=%10.4e, Pe=%10.4e' % \
>          (snr, error_sum/(FrameSize*nFrames), Pe)
>
>
> Octave m-file:
> % bpsk_sim.m - octave version
> clear
>
> tic
>
> SNR_MIN    = -1;
> SNR_MAX    = 10;
> FrameSize  = 100;
> Eb_No_dB = SNR_MIN:SNR_MAX;
>
> % signal vector
> s = ones(1,FrameSize);
> a = rand(1,FrameSize);
> a_i = find(a < 0.5);
> s(a_i) = -1;
>
> for snr=SNR_MIN:SNR_MAX
>
>   No = 10^(-snr/10.0);
>   Pe = 0.5*erfc(sqrt(1.0/No));
>   nFrames = ceil(200/FrameSize/Pe);
>   error_sum = 0;
>
>   for frame=1:nFrames
>
>     % noise
>     n = sqrt(No/2)*randn(1,FrameSize);
>     x = s + n;
>
>     y = sign(x);
>
>     err = find( y ~= s);
>     error_sum = error_sum + length(err);
>   end
>
>   fprintf('Eb_No_dB=%2d, BER=%10.4e, Pe=%10.4e\n', ...
>            snr, error_sum/(FrameSize*nFrames), Pe)
> end
> toc
>
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
>


-- 
French PhD student
Website : http://matthieu-brucher.developpez.com/
Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
LinkedIn : http://www.linkedin.com/in/matthieubrucher
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20080611/6af3b924/attachment.html>


More information about the SciPy-User mailing list