caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: malc <malc@pulsesoft.com>
To: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Benchmark: ref update vs argument passing
Date: Wed, 21 Nov 2001 03:20:12 +0300 (MSK)	[thread overview]
Message-ID: <Pine.LNX.4.21.0111210301370.6981-100000@oyster> (raw)
In-Reply-To: <slrn9vlqj1.cj1.qrczak@qrnik.zagroda>

On Tue, 20 Nov 2001, Marcin 'Qrczak' Kowalczyk wrote:

> 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
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


  reply	other threads:[~2001-11-21  0:22 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <9teme6$bn2$1@qrnik.zagroda>
2001-11-20 23:42 ` Marcin 'Qrczak' Kowalczyk
2001-11-21  0:20   ` malc [this message]
     [not found] <9tdsbg$qjc$1@qrnik.zagroda>
2001-11-20 15:37 ` Marcin 'Qrczak' Kowalczyk
2001-11-20 22:35   ` malc
2001-11-20 15:11 Stefano Zacchiroli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.21.0111210301370.6981-100000@oyster \
    --to=malc@pulsesoft.com \
    --cc=caml-list@inria.fr \
    --cc=qrczak@knm.org.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).