[
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: | 2001-12-11 (21:48) |
From: | Alain Frisch <frisch@c...> |
Subject: | Re: [Caml-list] Pairs vs. Records |
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> # 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