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 OAA22496; Wed, 23 Oct 2002 14:07:54 +0200 (MET DST) 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 OAA23704 for ; Wed, 23 Oct 2002 14:07:54 +0200 (MET DST) Received: from comtv.ru (comtv.ru [217.10.32.4]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g9NC7oD08573 for ; Wed, 23 Oct 2002 14:07:53 +0200 (MET DST) Received: from [10.0.66.9] ([10.0.66.9] verified) by comtv.ru (CommuniGate Pro SMTP 3.5.9) with ESMTP-TLS id 5058943; Wed, 23 Oct 2002 16:07:47 +0400 Date: Wed, 23 Oct 2002 16:08:09 +0400 (MSD) From: malc X-X-Sender: malc@home.oyster.ru To: Christophe TROESTLER cc: caml-list@inria.fr Subject: Re: [Caml-list] Re: float boxing (was: matrix-matrix multiply) In-Reply-To: <20021023.121626.64579491.debian00@tiscalinet.be> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Wed, 23 Oct 2002, Christophe TROESTLER wrote: > On Sun, 20 Oct 2002, Issac Trotts wrote: > > > > You might try converting your references to mutable fields. > > > > let x = ref 1.0 in > > let n = int_of_string Sys.argv.(1) in > > for i = 1 to n do x := !x +. 1.0 done > > > > ./ref 100000000 2.51s user 0.00s system 99% cpu 2.515 total > > > > type t = { mutable f:float };; > > let x = { f = 1.0 } in > > let n = int_of_string Sys.argv.(1) in > > for i = 1 to n do x.f <- x.f +. 1.0 done > > > > ./ref2 100000000 1.54s user 0.01s system 100% cpu 1.542 total > > A few questions in view of this. First, on my machine (AMD Athlon > 1GHz running GNU/Linux), the timings give a preference to ref.ml > > time ./ref 100000000 > real 0m1.279s user 0m1.280s sys 0m0.000s > time ./ref2 100000000 > real 0m1.411s user 0m1.380s sys 0m0.000s > > What could be a reason for that? I think the reason is simple, both are more or less nop operations, x or x.f is not used anywhere, hence no need to allocate the float. This short example highlights the difference: let useref n = let x = ref 1.0 in for i = 1 to n do x := !x +. 1.0 done; !x type t = { mutable f:float };; let userec n = let x = { f = 1.0 } in for i = 1 to n do x.f <- x.f +. 1.0 done; x.f let _ = let n = int_of_string Sys.argv.(2) in Printf.printf "%f\n" (if Sys.argv.(1) = "ref" then useref n else userec n) ref# time ./refrec rec 100000000 100000001.000000 real 0m2.283s user 0m2.280s sys 0m0.000s ref# time ./refrec ref 100000000 100000001.000000 real 0m1.916s user 0m1.910s sys 0m0.010s More or less same machine here. -- mailto:malc@pulsesoft.com ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners