From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id WAA29143; Tue, 11 Dec 2001 22:48:32 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f 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 WAA31401 for ; Tue, 11 Dec 2001 22:48:30 +0100 (MET) Received: from nef.ens.fr (nef.ens.fr [129.199.96.32]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id fBBLmT912182; Tue, 11 Dec 2001 22:48:29 +0100 (MET) Received: from clipper.ens.fr (clipper-gw.ens.fr [129.199.1.22]) by nef.ens.fr (8.10.1/1.01.28121999) with ESMTP id fBBLmOh80136 ; Tue, 11 Dec 2001 22:48:24 +0100 (CET) Received: from localhost (frisch@localhost) by clipper.ens.fr (8.9.2/jb-1.1) id WAA28311 ; Tue, 11 Dec 2001 22:48:22 +0100 (MET) Date: Tue, 11 Dec 2001 22:48:22 +0100 (MET) From: Alain Frisch To: Xavier Leroy cc: Willem Duminy , "Caml-List (E-mail)" Subject: Re: [Caml-list] Pairs vs. Records In-Reply-To: <20011211220928.C30744@pauillac.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 11 Dec 2001, Xavier Leroy wrote: > > I had a progarm that used pairs int*int as the basis of the primary data > > structure. After changing it to use records {row:int;col:int} the > > program runs slower. > > This is very surprising indeed, because the OCaml compilers generate > *exactly the same code* for building/accessing tuples and for > building/accessing records (with no mutable fields). I guess you know this better than I ;) but one can observe difference in generated code with pattern matching: # fun x y -> match (x,y) with (a,b) -> a + b;; closure L1, 0 return 1 restart L1: grab 1 acc 1 push acc 1 addint return 2 - : int -> int -> int = # fun x y -> match {row=x;col=y} with {row=a;col=b} -> a + b;; closure L1, 0 return 1 restart L1: grab 1 acc 1 push acc 1 makeblock 2, 0 push acc 0 getfield 1 push acc 1 getfield 0 addint return 3 Of course, it would be surprising to find this kind of code with records in a real program ... -- Alain ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr