This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

Memory allocation nano-benchmark.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2005-02-11 (09:20) From: FrÃ©dÃ©ric_Gava Subject: Re: [Caml-list] Memory allocation nano-benchmark.
```Hi,

> So, yours is slightly faster, but both are in the same ballpark
> and the C version is at least 4X faster.

The FAQ of OCaml says (http://caml.inria.fr/ocaml/numerical.html)

|       for j = 0 to N-1 do
|        for i = 0 to N-1 do
|            c.(i).(j) <- a.(i).(j) + b.(i).(j)
|          done
|        done
|but write:
|        for i = 0 to N-1 do
|          let row_a = a.(i) and row_b = b.(i) and row_c = c.(i) in
|          for j = 0 to N-1 do
|            row_c.(j) <- row_a.(j) + row_b.(j)
|          done
|       done

So for your code
>  for i = 0 to tablesize - 1 do
>    for j = 0 to tablesize - 1 do
>      for k = 0 to tablesize - 1 do
>        table.(i).(j).(k) <- (i+1)*(j+1)*(k+1)
>      done done done

You could write;
for i=0 to tablesize -1 do
let row1 = table.(i) in
for j=0 to tablesize -1 do
let row2 = row1.(j) do
for k=0 to tablesize -1 do
row2.(k) <- (i+1)*(j+1)*(k+1)
done done done

and peraps you will have a faster code. Try with "make_matrice" and without
and tell me please, I am interested by this subject.

Regards,