caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques-Henri Jourdan <jacques-henri.jourdan@ens.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Accessing record fields
Date: Sun, 15 Sep 2013 12:38:50 +0200	[thread overview]
Message-ID: <52358E3A.7030802@ens.fr> (raw)
In-Reply-To: <20130915103027.GA21344@jrm>

[-- Attachment #1: Type: text/plain, Size: 955 bytes --]

I think both are very close.

I would say that f is faster, because r.a is loaded only once. However,
this can increase register pressure...

I would say to use whichever is more easy to use a a given context, and
to tune specifically the code if this is the bottleneck: this is very
unlikely to be the performance bottleneck, and there won't be a big
performance improvement anyway...


-- 
JH

Le 15/09/2013 12:30, José Romildo Malaquias a écrit :
> Hello.
> 
> OCaml offers at least two ways of accessing a record field: using the
> dot notation, and doing pattern matching.
> 
> Does one of them deliver better performance than the other?
> 
> This may be relevant when a field is accessed multiple times.
> 
> For instance:
> 
>    type trec = { a : int; mutable b: int }
> 
>    let f {a;b} = a * a + b
> 
>    let g r = r.a * r.a + r.b
> 
> Which one would be preferred in this case: f or g?
> 
> Romildo
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 555 bytes --]

  reply	other threads:[~2013-09-15 10:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-15 10:30 José Romildo Malaquias
2013-09-15 10:38 ` Jacques-Henri Jourdan [this message]
2013-09-16  7:37   ` Goswin von Brederlow
2013-09-16  7:52 ` David MENTRE

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=52358E3A.7030802@ens.fr \
    --to=jacques-henri.jourdan@ens.fr \
    --cc=caml-list@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).