Version française
Home     About     Download     Resources     Contact us    
Browse thread
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: -- (:)
From: Christian Szegedy <szegedy@t...>
Subject: Re: [Caml-list] Memory allocation nano-benchmark.
Frédéric Gava wrote:

>Peraps test the following code (I do not have test it)
>  
>
OK:

memnew.ml

let test tablesize =
  let table = Array.create tablesize [| [| |] |] in
  for i=0 to tablesize - 1 do
     table.(i) <-   (  let tmp=Array.create tablesize [||]  in
    for j=0 to tablesize -1 do
        tmp.(j) <- Array.create tablesize 0
    done;
    tmp)
  done;

  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

let _ = test (int_of_string Sys.argv.(1))


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.