Utilities for timing macro expansion

_Utilities for timing macro expansion_

David Van Horn

This collection provides utilities for timing macro invocation and
expansion, analogous to the MzScheme utilities for collecting timing
information on procedure application and evaluation.

> (time-expand form) SYNTAX
  Expands form, collecting timing information, and reports the timing
  information directly to the current output port.  The result of
  expanding the time-expand form is the result of expanding form.
  Analogous to time but reports expansion time.

> (time-expand-invoke form) SYNTAX

  Expands form, collecting timing information.  The result of
  expanding the time-expand-invoke form is syntax for returning four
  values: the result of expanding form, and the CPU, real, and GC time
  spent expanding form.

To demonstrate the difference between timing the evaluation versus the
expansion of an expression, consider the following two definitions:

    (define-syntax (a-very-slow-transformer _)
      (sleep 1)
      (syntax (quote done)))

    (define (a-very-slow-procedure)
      (sleep 1)
      (quote done))

The macro a-very-slow-transformer performs a non-trivial computation
(ie, sleeping) at expansion time.  The macro then expands into an
expression that is trivial at run time (a symbolic constant).  On the
other hand, a-very-slow-procedure has a trivial expansion and
non-trivial run-time computation.  Using time and time-expand
demonstrates the difference:
   (time (a-very-slow-transformer))
   (time-expand (a-very-slow-transformer))

   (time (a-very-slow-procedure))
   (time-expand (a-very-slow-procedure))
Note that since expansion timing information is collected using time
and time-apply at expansion time, the reliability of the timing
numbers depends on the platform; see section 11.5.2 of "PLT MzScheme:
Language Manual" for more information on time accounting. If multiple
MzScheme threads are running, then the reported time may include work
performed by other threads.