home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / lisp / mcl / 1058 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  3.7 KB

  1. Path: sparky!uunet!wupost!sdd.hp.com!uakari.primate.wisc.edu!ames!sun-barr!apple!cambridge.apple.com!bill@cambridge.apple.com
  2. From: bill@cambridge.apple.com (Bill St. Clair)
  3. Newsgroups: comp.lang.lisp.mcl
  4. Subject: Re: PROGV mystery explained
  5. Message-ID: <9207221906.AA22087@cambridge.apple.com>
  6. Date: 22 Jul 92 20:50:06 GMT
  7. Sender: info-mcl-request@cambridge.apple.com
  8. Lines: 86
  9. Approved: comp.lang.lisp.mcl@Cambridge.Apple.C0M
  10. Full-Name: Bill St. Clair
  11. Original-To: David Kieras <kieras@engin.umich.edu>
  12. Original-Cc: kab@cambridge.apple.com, info-mcl@cambridge.apple.com
  13.  
  14. >Kim, your mention that EVAL does COMPILE by default prompts me to
  15. >ask about the performance implications.  How much, relatively &
  16. >intuitively, am I paying for this?   Would I be better off to
  17. >arrange it so that compile is not the default on EVAL?  If so,
  18. >what is the switch for it? Is this the same control as for the
  19. >toplevel READ-EVAL loop?
  20.  
  21. *COMPILE-DEFINITIONS*, which defaults to T, is the switch.
  22.  
  23. EVAL does not compile everything. It knows that many forms are "easy"
  24. to evaluate, and handles them. These include symbols, other atoms (which
  25. are self-evaluating), and lists with a car of QUOTE, PROGN, SETQ,
  26. EVAL-WHEN, IF, LOCALLY, SYMBOL-MACROLET, MACROLET, UNWIND-PROTECT,
  27. or any symbol which is not a special form (e.g. macros and regular
  28. functions). The compiler or the "real" evaluator is called whenever the user
  29. form specifies any kind of binding or explicitly requests the creation of
  30. a function object (This list is for 2.0 final. 2.0b1's EVAL invoked the compiler
  31. a little more often).
  32.  
  33. As to whether you're better off timewise running with *COMPILE-DEFINITIONS*
  34. set to NIL, that depends on what you're evaluating.
  35.  
  36. Here's an example where it doesn't matter, since the evaluated form is
  37. "simple" enough to grok without considering *COMPILE-DEFINITIONS*:
  38.  
  39. ? (let ((*compile-definitions* t))
  40.     (without-interrupts
  41.      (time (dotimes (i 1000) 
  42.              (eval '(+ 2 3))))))
  43. (DOTIMES (I 1000) (EVAL '(+ 2 3))) took 238 milliseconds (0.238 seconds) to run.
  44.  16000 bytes of memory allocated.
  45. NIL
  46. ? (let ((*compile-definitions* nil))
  47.     (without-interrupts
  48.      (time (dotimes (i 1000) 
  49.              (eval '(+ 2 3))))))
  50. (DOTIMES (I 1000) (EVAL '(+ 2 3))) took 238 milliseconds (0.238 seconds) to run.
  51.  16000 bytes of memory allocated.
  52. NIL
  53.  
  54. Here's an example where it is slightly faster to run with
  55. *COMPILE-DEFINITIONS* bound to NIL:
  56.  
  57. ? (let ((*compile-definitions* t))
  58.     (without-interrupts
  59.      (time
  60.       (eval '(let ((x 1)) x)))))
  61. (EVAL '(LET ((X 1)) X)) took 13 milliseconds (0.013 seconds) to run.
  62. Of that, 1 milliseconds (0.001 seconds) were spent in The Cooperative Multitasking Experience.
  63.  600 bytes of memory allocated.
  64. 1
  65. ? (let ((*compile-definitions* nil))
  66.     (without-interrupts
  67.      (time
  68.       (eval '(let ((x 1)) x)))))
  69. (EVAL '(LET ((X 1)) X)) took 6 milliseconds (0.006 seconds) to run.
  70.  800 bytes of memory allocated.
  71. 1
  72.  
  73. If you do more computation, the evaluator starts to show its sluggishness:
  74.  
  75. ? (let ((*compile-definitions* t))
  76.     (without-interrupts
  77.      (time
  78.       (eval '(let ((x 1))
  79.                (dotimes (i 1000) (incf x))
  80.                x)))))
  81. (EVAL '(LET ((X 1)) (DOTIMES (I 1000) (INCF X)) X)) took 91 milliseconds (0.091 seconds) to run.
  82. Of that, 1 milliseconds (0.001 seconds) were spent in The Cooperative Multitasking Experience.
  83.  1984 bytes of memory allocated.
  84. 1001
  85. ? (let ((*compile-definitions* nil))
  86.     (without-interrupts
  87.      (time
  88.       (eval '(let ((x 1))
  89.                (dotimes (i 1000) (incf x))
  90.                x)))))
  91. (EVAL '(LET ((X 1)) (DOTIMES (I 1000) (INCF X)) X)) took 552 milliseconds (0.552 seconds) to run.
  92.  2296 bytes of memory allocated.
  93. 1001
  94.  
  95. Note that the evaluator also conses a bit more in these two examples (I
  96. don't know if this is a general rule).
  97.