Browse thread
[Caml-list] Some clarifications to the language shootout page
-
Siegfried Gonzi
- Siegfried Gonzi
-
Pierre Weis
- Siegfried Gonzi
- Siegfried Gonzi
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Siegfried Gonzi <siegfried.gonzi@k...> |
| Subject: | Re: [Caml-list] Some clarifications to the language shootout page |
Pierre Weis wrote:
>Hi,
>
>I try to answer your post in a fair manner: I think the Caml and
>Scheme code are not equivalent (hence the figures you observed). I
>give the Caml code that is (in my mind) equivalent to the Scheme
>code. I would be glad if you could run it on your machine to complete
>your comparison (and may be modify your conclusions).
>
Pierre Weis translated the Bigloo version to:
====
=========================
Ocaml version
obtained from the original Scheme fast version: (C) P. Weis
usage: ocamlopt -unsafe -inline 9 mm_scm.ml
time ./a.out
=========================
let make_matrix rows cols =
let mx = Array.make rows [||] in
let count = ref 1.0 in
for i = 0 to rows - 1 do
let row = Array.make cols 0.0 in
for j = 0 to cols - 1 do
row.(j) <- !count;
count := !count +. 1.0
done;
mx.(i) <- row
done;
mx;;
(* Don't know why there is this dead code into the Scheme version *)
let num_cols mx =
let row = mx.(0) in
Array.length row;;
(* Don't know why there is this dead code into the Scheme version *)
let num_rows mx =
Array.length mx;;
let mmult rows cols m1 m2 =
let m3 = Array.make rows [||] in
for i = 0 to rows - 1 do
let m1i = m1.(i) in
let row = Array.make cols 0.0 in
for j = 0 to cols - 1 do
let v = ref 0.0 in
for k = 0 to cols - 1 do
v := !v +. m1i.(k) *. m2.(k).(j);
done;
row.(j) <- !v;
done;
m3.(i) <- row;
done;
m3;;
let do_main size =
let mm = ref [||] in
let m1 = make_matrix size size in
let m2 = make_matrix size size in
mm := mmult size size m1 m2;
let r0 = !mm.(0)
and r2 = !mm.(2)
and r3 = !mm.(3)
and r4 = !mm.(4) in
Printf.printf "%f %f %f %f\n" r0.(0) r2.(3) r3.(2) r4.(4);;
do_main 512;;
====
This new situation ends up in:
I did things on my stationary machine: Pentium II 450MHz, 256MB RAM,
SuSE Linux 8.0
bigloo -Obench bench.scm : 23s/23s/0.1s
g++ -O6 bench.scm: 7s/7s/0.03s
ocamlopt -unsafe -inline 9 bench1.ml: 18s/18s/0.01
;; Weis's version:
ocamlopt unsafe -inline 9 bench2.ml : 14s/14s/0.01
Maybe the Scheme version could a little bit tweaked too. I am not sure.
One short note: The Scheme version is portable from one Scheme
implementation to the next and one could write a small macro which
decides whether to use normal Scheme operators or Bigloo's native ones.
S. Gonzi
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners