home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / function / 961 < prev    next >
Encoding:
Text File  |  1992-07-27  |  3.3 KB  |  70 lines

  1. Newsgroups: comp.lang.functional
  2. Path: sparky!uunet!mcsun!sunic!kth.se!dentex.tds.kth.se!kff
  3. From: kff@dentex.tds.kth.se (Karl-Filip Faxen)
  4. Subject: Re: Gabriel benchmarks in a functional language?
  5. Message-ID: <1992Jul27.153205.15016@kth.se>
  6. Sender: usenet@kth.se (Usenet)
  7. Nntp-Posting-Host: dentex.tds.kth.se
  8. Reply-To: kff@dentex.tds.kth.se (Karl-Filip Faxen)
  9. Organization: Royal Institute of Technology, Stockholm, Sweden
  10. References: <DBH.92Jul23152442@wombat.doc.ic.ac.uk> <DELACOUR.92Jul23110032@waxwing.parc.xerox.com>
  11. Date: Mon, 27 Jul 1992 15:32:05 GMT
  12. Lines: 56
  13.  
  14. In article <DELACOUR.92Jul23110032@waxwing.parc.xerox.com>, delacour@waxwing.parc.xerox.com (Vincent Delacour) writes:
  15.  
  16. |> Francis Dupont of INRIA has translated some of the Gabriel benchmarks
  17. |> in a lazy variant of CAML. He found that, eg, the Boyer test program
  18. |> was running faster in lazy mode than in eager mode, because most of
  19. |> the lists it creates do not get used! 
  20. |> 
  21. |> Feel free to consider this a proof that lazyness is superior to
  22. |> eagerness <8^]. IMO this is at best a proof that benchmarks are often
  23. |> meaningless.
  24.  
  25. I haven't seen the code for the Gabriel benchmarks, but I can see three
  26. reasons for this result:
  27.  
  28. (1) The benchmaks throws away their results, since they are just
  29.     benchmarks. This is an old problem with optimizing compilers,
  30.     that they eliminate 'unnecessary' code. It is interresting to
  31.     note that in this sense, any lazy implementation will behave
  32.     like a heavily optimizing implementation of an imperative 
  33.     language. This is often referred to as the 'self optimizing
  34.     property' of lazy evaluation.
  35.  
  36.     The cure is, of course, to rewrite the benchmarks to do something
  37.     with their result (eg write it to a file).
  38.  
  39. (2) The code is probably written so that datastructures are built
  40.     and traversed. Now, these may sometimes not be traversed in their
  41.     entirety, with the choice of what parts to traverse or not being
  42.     data dependent. Also, these datastructures may be shared, ie 
  43.     traversed by several different functions. Then lazy evaluation
  44.     guarantees that only the parts that actually are traversed will
  45.     be constructed, and then they will only be constructed once.
  46.  
  47.     In a strict language, the datastructures in question will always
  48.     be constructed in their entirety and only subsequently be
  49.     traversed. The only way to get the behaviour of the lazy language
  50.     is to merge the producer and consumers of the datastrucure. This
  51.     may be hideously difficult and lead to very messy code, especially
  52.     if there are multiple consumers (sharing), and one wishes to avoid
  53.     recomputation by every consumer. In any case, even if there is only
  54.     one consumer, modularity is greatly compromised.
  55.  
  56.     Thus laziness allows you to separate the problem of how to build
  57.     the datastructure from the problem of determining how much of it 
  58.     will actually be needed.
  59.  
  60. (3) Sometimes, the evaluation order of a lazy evaluator is more 
  61.     efficient than that of a strict evaluator, since the lazy evaluator
  62.     might build and traverse a datastructure incrementally using a 
  63.     constant amount of heap space and increasing the locality of the
  64.     computation. This might have been such a case.
  65.  
  66.  
  67. Karl-Filip
  68. -----------------------------------------------------------------------
  69. Make the frequent case fast, and the fast case frequent!
  70.