Version franaise
Home About Download Resources Contact us
Browse thread
Re: speed versus C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: STARYNKEVITCH Basile <Basile.Starynkevitch@c...>
Subject: Re: speed versus C

in september 1998, on a previous job (in the same organization, CEA,
but in a different department), I did work (several months) on
benchmarking various langages and implementations. My former collegue
Emmanuel Dorlet asked me to mail some timing results.

My tiny benchmark was related to computing the sum of inverses of
integers (a serie converging to pi^2/6 as we all know)

let onsquare i j =
  let ii = float i
  and jj = float j
  in ii /. ( jj *. jj)
;;
 
let test2 n p =
  for i=1 to p do
    let rec loop j s =
      if (j <= 0) then s
      else loop (j-1) (s +. onsquare i j)
    in
    let s = loop n 0.0 in
    Format.printf "n=%d i=%d s=%f\n" n i s
  done
;;

On that time I benched ocaml 1.07 or 2.00. Plateform was a PC/Linux
(Redhat-5.2, Pentium II 300? MHz). Here are the results, mesuring the
internal iteration time (running equivalent of test2 1000000 50, or
test2 10000 50 for slow implementations), which is the total CPU time
divided by n*p


Notice that this benchmark is a numerical test, and numbers is a
domain where Ocaml is rather poor (integers are tagged, and floating
point numbers are often boxed)

I tested ocaml in an imperative (for loop with reference) and
functional (terminal recursion)


langage impl.      time/iteration    slowdown/C
                    CPU microsec

Fortran77 compiled       0.124s      0.95     
C compiled               0.131s      1    
Ocaml1.07 compiled       0.408s      3.11    
Java {JDK1.1.5}          1.31s       10    
Ocaml {1.07 fonctionnal} 1.92s       14.66   
Ocaml {1.07 imprative}  2.014s      15.37   
Ocaml {2.00 fonctionnal} 2.112s      16.12   
Lua 3.1                  3.43s       26.18   
Scheme {vscm 0.4}        16.64s      127   
Python 1.5               17.93s      137   
Perl 5.003               18.62s      142   
Scheme {guile 1.2}       34.37s      262   
Tcl8.0                   158.3s      1208   
Gibiane                  2656s       20275  


For your information, Gibiane was an internal scripting langage
(simliar to Tcl, implemented in a Fortran dialect) which should now be
dismissed.


My personal opinion is that there are domain (such as tree
manipulation) where Ocaml outperform C or C++ (but that did not
convince my current boss).

Choosing Ocaml is not a technical issue. It is a managerial and
psychological issue. I am bad on both.

Regards.

N.B. Any opinions expressed here are only mine, and not of my organization.
N.B. Les opinions exprimees ici me sont personnelles et n engagent pas le CEA.

---------------------------------------------------------------------
Basile STARYNKEVITCH   ----  Commissariat  l Energie Atomique 
DTA/LETI/DEIN/SLA * CEA/Saclay b.528 (p111f) * 91191 GIF/YVETTE CEDEX * France
phone: 1,69.08.60.55; fax: 1.69.08.83.95 home: 1,46.65.45.53
email: Basile point Starynkevitch at cea point fr