caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benoit de Boursetty <debourse@email.enst.fr>
To: caml-list@inria.fr
Subject: Lazy evaluation & performance
Date: Sun, 20 Feb 2000 13:54:16 +0100 (MET)	[thread overview]
Message-ID: <Pine.GSO.4.02.10002201143320.12460-100000@young.enst.fr> (raw)

Hello,

Has anybody done benchmarks to eval the cost of lazy computation
encapsulation, in terms of time, memory, garbage collection? I have no
idea of how this is implemented...

Here's my personal case :

There is a function f which I want to compute for several arguments
x_1,...x_n.

let f x =
  [beginning]
  let intermediate_value = ... in
  [end]

only that I want to compute it thoroughly just for the x_i that has the
highest intermediate_value among x_i's. This intermediate value is used
anyway for the [end] part.

Naive design (design a):

let f x =
  [beginning]
  let intermediate_value = ... in
  (intermediate_value, lazy [end])
 
the lazy computation of the [end] being forced only for the x_i that has
the highest intermediate_value

Another possible design (less elegant) (design b):

let intermediate_value x =
  [beginning]
  let intermediate_value = ... in
  intermediate_value

let f x =
  [beginning]
  [end]

I compute the intermediate value and then recompute all over again
for the x I want to compute.

Comparison of time costs:

if
  B is the cost for [beginning]
  E is the cost for [end]
  L is the cost for encapsulating the lazy computation of [end]
then
design a costs n*(B+L) + E
design b costs (n+1)*B + E
(very roughly I suppose)

Clearly, deciding which design to adopt is a trade-off depending on n, B,
L. I suppose L also depends on the number of results from [beginning] that
the computer will need to "remember" for [end]? Also, encapsulating lazy
computations means more memory allocation, means more garbage collecting,
doesn't it?

In my case the efficiency bottleneck is E not B, and n is about 10 (i.e.
high) so I'm not expecting a wonderful overall time gain. I'm just
wondering if it's costly to implement it in the way that corresponds best
to reality (design a). "B" is only a dozen flops.

Could anybody give me a hint about the order of magnitude of L?

Thanks very much in advance for your answers.

Benoit de Boursetty.



             reply	other threads:[~2000-02-21 17:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-20 12:54 Benoit de Boursetty [this message]
2000-03-03 12:45 Damien Doligez

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.02.10002201143320.12460-100000@young.enst.fr \
    --to=debourse@email.enst.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).