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 AAA07993; Wed, 21 Nov 2001 00:41:42 +0100 (MET) 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 AAA02707 for ; Wed, 21 Nov 2001 00:41:41 +0100 (MET) Received: from mail.mimuw.edu.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id fAKNfaT24704 for ; Wed, 21 Nov 2001 00:41:37 +0100 (MET) Received: (from news@localhost) by mail.mimuw.edu.pl (PLD/8.9.3) id AAA17602 for caml-list@inria.fr; Wed, 21 Nov 2001 00:42:28 +0100 X-Authentication-Warning: qrnik.zagroda: news set sender to Marcin 'Qrczak' Kowalczyk using -f From: "Marcin 'Qrczak' Kowalczyk" Subject: Re: [Caml-list] Benchmark: ref update vs argument passing Date: Tue, 20 Nov 2001 23:42:25 +0000 (UTC) Organization: Klub Nieszkodliwych =?iso-8859-2?Q?Manjak=F3w?= Message-ID: References: <9teme6$bn2$1@qrnik.zagroda> X-Trace: qrnik.zagroda 1006299745 12898 192.168.0.1 (20 Nov 2001 23:42:25 GMT) X-Complaints-To: abuse@localhost NNTP-Posting-Date: Tue, 20 Nov 2001 23:42:25 +0000 (UTC) User-Agent: slrn/0.9.7.2 (Linux) To: caml-list@inria.fr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 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. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ QRCZAK ------------------- 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