caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Memory allocation nano-benchmark.
@ 2005-02-10 15:15 Christian Szegedy
  2005-02-10 14:47 ` [Caml-list] " Frédéric Gava
                   ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: Christian Szegedy @ 2005-02-10 15:15 UTC (permalink / raw)
  To: caml-list

Let us look at another example where ocaml not really shines:

mem.ml:

let test tablesize =
   let table =
     Array.init tablesize (fun i ->
       Array.init tablesize (fun j ->
         Array.init tablesize (fun k ->
           ((i+1)*(j+1)*(k+1))))) in ()

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


mem.c:

void test(int tablesize)
{

    int i;
    int ***table = (int ***)malloc(tablesize *sizeof(int **));

    for( i=0; i<tablesize ; i++ )
    {
       int j;
       table[i] = (int **)malloc(tablesize * sizeof(int *));

       for ( j=0 ; j < tablesize ; j++ )
       {
          int k;
          table[i][j] = (int *)malloc(tablesize * sizeof(int));

          for ( k =0 ; k < tablesize ; k++ )
          {
             table[i][j][k] = (i+1)*(j+1)*(k+1);
          }
       }
    }
}


int main(int argc,char *argv[])
{
    int i;

    if( argc < 2 ) { return -1; }

    test(atoi(argv[1]));

    return 0;
}

On an old sub-Ghz Pentium laptop:

ocamlopt -unsafe -inline 40 mem.ml
time a.out 500
real    0m4.229s
user    0m3.870s
sys     0m0.360s


gcc -O3 -fomit-frame-pointer mem.c
time a.out 300
real    0m0.935s
user    0m0.420s
sys     0m0.500s



On a new Opteron box (OK, it's cheating, becasuse OCamls ints
are 64 bits, but there is still no disk-cache involved since
it has 64gigs :)):

gcc -O3 -fomit-frame-pointer mem.c
time ./a.out 500
real    0m0.803s
user    0m0.224s
sys     0m0.575s


ocamlopt -unsafe -inline 40 mem.ml
time ./a.out 500
real    0m8.651s
user    0m7.270s
sys     0m1.357s




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

end of thread, other threads:[~2005-02-16 10:56 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-10 15:15 Memory allocation nano-benchmark Christian Szegedy
2005-02-10 14:47 ` [Caml-list] " Frédéric Gava
2005-02-10 15:19   ` skaller
2005-02-10 16:36     ` Frédéric Gava
2005-02-10 17:56       ` Frédéric Gava
2005-02-10 19:56         ` Christian Szegedy
2005-02-10 23:58           ` Frédéric Gava
2005-02-11  9:22           ` Frédéric Gava
2005-02-11 13:04             ` skaller
2005-02-11 13:33               ` skaller
2005-02-11 21:07               ` Oliver Bandel
2005-02-12  0:44                 ` skaller
2005-02-15 14:17                   ` Frédéric Gava
2005-02-15 19:19                     ` Christian Szegedy
2005-02-15 20:51                     ` Jon Harrop
2005-02-16  8:19                       ` Ville-Pertti Keinonen
2005-02-16  9:54                         ` Jon Harrop
2005-02-16 10:56                           ` Ville-Pertti Keinonen
2005-02-11  0:55       ` skaller
2005-02-10 14:56 ` Jon Harrop
2005-02-10 15:32   ` Ville-Pertti Keinonen
2005-02-10 14:59 ` John Prevost
2005-02-10 16:50   ` Marwan Burelle
2005-02-10 19:20     ` Christian Szegedy
2005-02-10 19:40       ` Jon Harrop
2005-02-11 11:26       ` Oliver Bandel
2005-02-12 13:42         ` Christian Szegedy
2005-02-11  1:04     ` skaller
2005-02-11 11:28       ` Oliver Bandel
2005-02-12  0:01         ` Guillaume
2005-02-12  0:36         ` 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).