Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Benchmark: ref update vs argument passing
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] Benchmark: ref update vs argument passing
Wed, 21 Nov 2001 01:35:53 +0300 (MSK), malc <malc@pulsesoft.com> 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