caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alain Frisch <frisch@clipper.ens.fr>
To: Xavier Leroy <xavier.leroy@inria.fr>
Cc: Willem Duminy <WDuminy@mweb.com>,
	"Caml-List (E-mail)" <caml-list@inria.fr>
Subject: Re: [Caml-list] Pairs vs. Records
Date: Tue, 11 Dec 2001 22:48:22 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.4.33.0112112239470.16776-100000@clipper.ens.fr> (raw)
In-Reply-To: <20011211220928.C30744@pauillac.inria.fr>

On Tue, 11 Dec 2001, Xavier Leroy wrote:

> > I had a progarm that used pairs int*int as the basis of the primary data
> > structure.  After changing it to use records {row:int;col:int} the
> > program runs slower.
>
> This is very surprising indeed, because the OCaml compilers generate
> *exactly the same code* for building/accessing tuples and for
> building/accessing records (with no mutable fields).

I guess you know this better than I ;) but one can observe difference in
generated code with pattern matching:

# fun x y -> match (x,y) with (a,b) -> a + b;;
        closure L1, 0
        return 1
        restart
L1:     grab 1
        acc 1
        push
        acc 1
        addint
        return 2

- : int -> int -> int = <fun>
# fun x y -> match {row=x;col=y} with {row=a;col=b} -> a + b;;
        closure L1, 0
        return 1
        restart
L1:     grab 1
        acc 1
        push
        acc 1
        makeblock 2, 0
        push
        acc 0
        getfield 1
        push
        acc 1
        getfield 0
        addint
        return 3


Of course, it would be surprising to find this kind of code with
records in a real program ...


-- 
  Alain

-------------------
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-12-11 21:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-11 14:36 Willem Duminy
2001-12-11 21:09 ` Xavier Leroy
2001-12-11 21:48   ` Alain Frisch [this message]
2001-12-13 20:26     ` Xavier Leroy

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.GSO.4.33.0112112239470.16776-100000@clipper.ens.fr \
    --to=frisch@clipper.ens.fr \
    --cc=WDuminy@mweb.com \
    --cc=caml-list@inria.fr \
    --cc=xavier.leroy@inria.fr \
    /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).