Fortran comparison Re: [SciPy-dev] scipy.weave versus simple C++.

Prabhu Ramachandran prabhu at aero.iitm.ernet.in
Sun Jan 13 03:45:32 CST 2002


hi,

>>>>> "eric" == eric  <eric at scipy.org> writes:

    eric> Hey Pearu, <snip Fortran compared to Blitz>
    >> > > Iterations took 6.12530398369 seconds.  > > Fortran
    >> iterations took 3.15447306633 seconds.

    eric> I've rewritten the code in C++ as quickly as I know how and
    eric> added a few optimizations.  It has the same errors as the
    eric> previous example, but, again, is useful for
    eric> benchmarking. (maybe Prabhu will fix my bugs in this code
    eric> also. :) The results are as follows:

I've added all the stuff to my version of the code -- I still have to
remove the mayavi dependency and maybe clean it up a bit but here are
some prelim results.  I have the following solution procedures.

  (a) slow Python - normal for loops and stuff.

  (b) numeric -- just there for testing the speed the results will be
  different since it uses temporaries.

  (c) blitz -- this uses the silly way to compute the error.

  (d) inline -- thanks to Eric's code slightly modfied.

  (e) fastinline -- Eric's new version (the only bug was that err
  should be set to zero before the loop).

  (f) fortran -- This is Pearu's version pretty much verbatim.


 (1) I made pretty sure that the output of
 weave/inline/fastinline/fortran are all very much alike.  I found
 that there is some loss of precision in the fortan code but the
 results are pretty much identical.  The errors were different by very
 small numbers.  For a 500 by 500 grid I computed a few iterations
 using weave/inline/fastinline and compared them with the fortan
 results and they are the same to within 1 part in 1e-15 or something.

 (2) Here are the results of speed tests.  I create a 500x500 grid and
 run it for 100 iterations.  I do two runs and average the results.
 Just for the heck of it I ran the slow time step for 5 iterations
 multiplied the result by 20 to get total time for 100 iterations.

   slow:      1847.60 s == (time for 5 iterations)*20
   numeric:     29.5  s
   blitz:        9.75 s
   inline:       4.60 s    
   fortran:      3.24 s
   fastinline:   2.92 s


Fastinline is about 630 times faster than the normal slow for loop!
Wow! unbelievable!!

Obviously, more speedup can be achieved but its clear that blitz,
inline, fortran and fastinline are big winners and that they are all
reasonably close.  inline and fortran are about 40% off which is not
bad at all.  fastinline is about 10% faster than fortran but the code
is dirty.

prabhu



More information about the Scipy-dev mailing list