Browse thread
Memory allocation nano-benchmark.
-
Christian Szegedy
- Frédéric_Gava
- Jon Harrop
- John Prevost
[
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,
I think it is due to tablesize^3 applications of functions that are not
present in the C code. But the number of line codes makes me prefer the
ocaml one.
Regards,
Frédéric Gava
> 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
>
>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>