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 BAA07983; Wed, 21 Nov 2001 01:22:27 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA08535 for ; Wed, 21 Nov 2001 01:22:26 +0100 (MET) Received: from comtv.ru (mail.comtv.ru [217.10.32.4]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fAL0MQb24019 for ; Wed, 21 Nov 2001 01:22:26 +0100 (MET) Received: from [10.2.64.72] (HELO oyster2) by comtv.ru (CommuniGate Pro SMTP 3.4.7) with ESMTP id 1170108; Wed, 21 Nov 2001 03:22:20 +0300 Date: Wed, 21 Nov 2001 03:20:12 +0300 (MSK) From: malc X-Sender: malc@oyster To: "Marcin 'Qrczak' Kowalczyk" cc: caml-list@inria.fr Subject: Re: [Caml-list] Benchmark: ref update vs argument passing In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Tue, 20 Nov 2001, Marcin 'Qrczak' Kowalczyk wrote: > Wed, 21 Nov 2001 01:35:53 +0300 (MSK), malc pisze: > > >> let use_refs' time = > >> let rif = ref 0 in > >> for i = 0 to time - 1 do rif := !rif + 1 done; > >> !rif > > let use_refs' time = > > let rif = ref 0 in > > for i = 0 to pred time do incr rif done; > > !rif > > The generated code is exactly the same :-P Precisely ;) It's more "camlish" in my opinion, which is why i couldnt resist posting it. > > But none of the following produces optimal code (judging by looking > at the generated code): > > let current = ref 0 > let next1 () = let x = !current in incr current; x > let next2 () = let x = !current in current := x + 1; x > let next3 () = incr current; !current > let next4 () = let x = !current + 1 in current := x; x > > Moreover, making the counter private on the declaration level: > > let next1 = > let current = ref 0 in > fun () -> let x = !current in incr current; x > > yields worse code, even though the semantics is the same. Semantics are not the same here: first 'current' is module global and statically allocated in module storage. Second 'current' is lexically bound. When i was playing with Doug Bagley's "Great Computer Language Shootout" http://www.bagley.org/~doug/shootout/bench/sumcol/ , i found that no matter how hard i try to invent some ingenious summing function caml generated code leaves a lot to be desired. (I think this holds for any use of global references). P.S. When playing with those functions you might find -dcmm option useful. -- mailto:malc@pulsesoft.com ------------------- 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