Browse thread
Memory allocation nano-benchmark.
[
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: | Frédéric_Gava <frederic.gava@w...> |
| Subject: | Re: [Caml-list] Memory allocation nano-benchmark. |
Hi,
There is a function in the stdlid for have a beter code:
let test tablesize =
let table = Array.create tablesize [| [| |] |] in
for i=0 to tablesize - 1 do
table.(i) <- Array.make_matrix tablesize tablesize 0
done;
...
smaller code no ? ;-)
> The results (on an AMD 2000XP):
>
> chris@gentoo:~/test$ ocamlopt -unsafe -inline 40 memnew.ml
> chris@gentoo:~/test$ a.out 300
> chris@gentoo:~/test$ time a.out 300
> real 0m1.560s
> user 0m1.391s
> sys 0m0.105s
>
> chris@gentoo:~/test$ ocamlopt -unsafe -inline 40 mem.ml
> chris@gentoo:~/test$ time a.out 300
> real 0m2.106s
> user 0m1.904s
> sys 0m0.106s
>
> chris@gentoo:~/test$ gcc -O3 -fomit-frame-pointer mem.c
> chris@gentoo:~/test$ time a.out 300
> real 0m0.380s
> user 0m0.283s
> sys 0m0.072s
>
> So, yours is slightly faster, but both are in the same ballpark
> and the C version is at least 4X faster.
:-(
Peraps due to the fact that "int" are boxed. Try to give "options you give
to gcc" to ocamlopt
to link optimized code. Else I do not know how to optimize this code "in a
pure ocaml way" (i.e without trick with C code). Is caml guru, wizards or
ocaml's creators have an idea ?
Regards,
Frédéric Gava