From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 07646BC88 for ; Thu, 10 Feb 2005 15:45:30 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1AEjTFB022947 for ; Thu, 10 Feb 2005 15:45:29 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA22890 for ; Thu, 10 Feb 2005 15:45:29 +0100 (MET) Received: from smtp10.wanadoo.fr (smtp10.wanadoo.fr [193.252.22.21]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j1AEjT7D022942 for ; Thu, 10 Feb 2005 15:45:29 +0100 Received: from me-wanadoo.net (unknown [127.0.0.1]) by mwinf1004.wanadoo.fr (SMTP Server) with ESMTP id E769C240017A for ; Thu, 10 Feb 2005 15:45:28 +0100 (CET) Received: from nono (ARouen-106-1-2-213.w217-128.abo.wanadoo.fr [217.128.67.213]) by mwinf1004.wanadoo.fr (SMTP Server) with SMTP id 96FA22400168 for ; Thu, 10 Feb 2005 15:45:28 +0100 (CET) X-ME-UUID: 20050210144528618.96FA22400168@mwinf1004.wanadoo.fr Message-ID: <005101c50f7f$6db0e560$d54380d9@mshome.net> From: =?iso-8859-1?Q?Fr=E9d=E9ric_Gava?= To: References: <420B7A7E.90504@or.uni-bonn.de> Subject: Re: [Caml-list] Memory allocation nano-benchmark. Date: Thu, 10 Feb 2005 15:47:21 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Miltered: at nez-perce with ID 420B7389.002 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 420B7389.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; gava:01 gava:01 caml-list:01 ocaml:01 ocaml:01 argv:01 malloc:01 sizeof:01 malloc:01 sizeof:01 argc:01 char:01 argv:01 argc:01 atoi:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: 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 { > 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 >