Re: speed versus C

From: STARYNKEVITCH Basile (Basile.Starynkevitch@cea.fr)
Date: Thu Oct 07 1999 - 15:00:13 MET DST


From: STARYNKEVITCH Basile <Basile.Starynkevitch@cea.fr>
Date: Thu, 7 Oct 1999 15:00:13 +0200 (MET DST)
To: caml-list@inria.fr
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.124Ás 0.95
C compiled 0.131Ás 1
Ocaml1.07 compiled 0.408Ás 3.11
Java {JDK1.1.5} 1.31Ás 10
Ocaml {1.07 fonctionnal} 1.92Ás 14.66
Ocaml {1.07 impÚrative} 2.014Ás 15.37
Ocaml {2.00 fonctionnal} 2.112Ás 16.12
Lua 3.1 3.43Ás 26.18
Scheme {vscm 0.4} 16.64Ás 127
Python 1.5 17.93Ás 137
Perl 5.003 18.62Ás 142
Scheme {guile 1.2} 34.37Ás 262
Tcl8.0 158.3Ás 1208
Gibiane 2656Ás 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



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:26 MET