caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* speed versus C
@ 1999-10-03 21:35 Jan Brosius
  1999-10-04 21:59 ` skaller
                   ` (2 more replies)
  0 siblings, 3 replies; 36+ messages in thread
From: Jan Brosius @ 1999-10-03 21:35 UTC (permalink / raw)
  To: OCAML

Hi, is there anything known about the efficiency of compiled Ocaml code
compared with C/C++

Thanks

Jan




^ permalink raw reply	[flat|nested] 36+ messages in thread
* Re: speed versus C
@ 1999-10-07 13:00 STARYNKEVITCH Basile
  0 siblings, 0 replies; 36+ messages in thread
From: STARYNKEVITCH Basile @ 1999-10-07 13:00 UTC (permalink / raw)
  To: caml-list

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=us-ascii, Size: 2856 bytes --]


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 




^ permalink raw reply	[flat|nested] 36+ messages in thread
* Re: speed versus C
@ 1999-10-08  6:57 Pascal Brisset
  0 siblings, 0 replies; 36+ messages in thread
From: Pascal Brisset @ 1999-10-08  6:57 UTC (permalink / raw)
  To: caml-list


Une petit benchmark qui pourrait être à l'avantage de C: crible d'Eratosthène

--8<------------------------------------------
let n = int_of_string Sys.argv.(1) in
let crible = Array.create n true in
for i = 2 to n-1 do
  if crible.(i)
  then begin
    for j = 2 to (n-1)/i do
      crible.(i*j) <- false
    done
  end
done
--8<------------------------------------------


--8<------------------------------------------
main(int argc, char **argv)
{
  int n = atoi(argv[1]);
  int crible[n], i, j;
  for(i=0; i < n; i++) { crible[i] = 1; }
  for(i = 2; i < n; i++) {
    if (crible[i]) {
      for(j = 2; j <= (n-1)/i; j++) {
	crible[i*j] = 0;
      }
    }
  }
}
--8<------------------------------------------


Sur un Pentium 400Mhz sous Linux:

sepia[854]% gcc -O4 premiers.c
sepia[855]% time a.out 2000000
0.860u 0.030s 0:00.91 97.8%     0+0k 0+0io 91pf+0w
sepia[856]% ocamlopt premiers.ml
sepia[857]% time a.out 2000000
0.910u 0.040s 0:00.96 98.9%     0+0k 0+0io 133pf+0w

 Seulement 5% de différence sur des opérations basiques entières, pas de quoi
se priver.
 Pour des benchmarks sophistiqués, méfions-nous; on a trop souvent tendance à
comparer une solution (en C) développée sur plusieurs années par des experts
à une solution (en Caml) écrite sur un coin de table « juste pour voir » ...

--Pascal Brisset




^ permalink raw reply	[flat|nested] 36+ messages in thread
[parent not found: <Pine.LNX.4.03.9910081713230.31666-100001@post.tepkom.ru>]
* Re: speed versus C
@ 1999-10-12 13:21 Damien Doligez
  1999-10-12 20:42 ` skaller
  0 siblings, 1 reply; 36+ messages in thread
From: Damien Doligez @ 1999-10-12 13:21 UTC (permalink / raw)
  To: caml-list

>From: skaller <skaller@maxtal.com.au>

>        However, C++ allows finalisation and ocaml doesn't,
>which is a serious problem in ocaml when it is needed.
>
>        I would very much like to see some discussion by ocaml experts
>(not me!) leading to a standard solution to this problem, probably

As far as I can tell, you've been asking for three things:

1. Efficient finalization, with finalization functions written in O'Caml.
2. Correct finalization of circular references.
3. Immediate finalization: as soon as a value becomes unreachable, the
   finalization function is called.

I don't know how to get all three together.  It is likely that we'll
have 1 and 2 in a future release of O'Caml.

-- Damien




^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~1999-10-13  7:11 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-10-03 21:35 speed versus C Jan Brosius
1999-10-04 21:59 ` skaller
1999-10-05 23:22   ` chet
1999-10-06 10:22     ` skaller
1999-10-05 20:20 ` Gerd Stolpmann
1999-10-06 15:21   ` William Chesters
1999-10-06 22:49     ` Gerd Stolpmann
1999-10-07 10:26       ` Michel Quercia
1999-10-07 10:46       ` William Chesters
1999-10-07 15:48         ` Pierre Weis
1999-10-07 19:21         ` Gerd Stolpmann
1999-10-08  0:26           ` William Chesters
1999-10-10 16:27             ` Gerd Stolpmann
1999-10-10 20:48               ` William Chesters
1999-10-10 23:54                 ` Alain Frisch
1999-10-11 17:58                   ` William Chesters
1999-10-12 14:36                     ` Ocaml Machine (was Re: speed versus C) Alain Frisch
1999-10-12 15:32                       ` David Monniaux
1999-10-12 15:42                         ` Alain Frisch
1999-10-11 19:32                   ` speed versus C John Prevost
1999-10-11 20:50                 ` Gerd Stolpmann
1999-10-12 20:07                   ` skaller
1999-10-08  9:56           ` Pierre Weis
1999-10-07 15:25     ` Markus Mottl
1999-10-07  6:56   ` skaller
1999-10-07 12:37     ` Xavier Urbain
1999-10-07 22:18     ` Gerd Stolpmann
1999-10-08 19:15       ` skaller
1999-10-08 13:40   ` Anton Moscal
1999-10-06  7:58 ` Reply to: " Jens Olsson
1999-10-07 13:00 STARYNKEVITCH Basile
1999-10-08  6:57 Pascal Brisset
     [not found] <Pine.LNX.4.03.9910081713230.31666-100001@post.tepkom.ru>
1999-10-10  4:51 ` skaller
1999-10-11  9:08   ` Anton Moscal
1999-10-12 13:21 Damien Doligez
1999-10-12 20:42 ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).