On this page:
timer
profile
with-timer
timer-value
timer-reset!
current-timer
all-timers
define-timer
Version: 4.2.0.5

23 Profiling tools

 (require (planet untyped/unlib/profile))

Simple profiling tools.

(struct timer (name))
  name : symbol?

Structure used to record a running total time. Only one timer can be running at a time per thread. The accumulated time associated with a timer can be retrieved using timer-value and printed by printing the timer.

(profile timer fn arg ...)  any
  timer : timer?
  fn : procedure?
  arg : any

Applies fn to args and returns the result. Measures the time taken to apply fn and adds it to the running total in timer. Timers are only updated when control passes into or out of a profile form.

Examples:

  > (define t1 (make-timer 't1))
  > (profile t1 foldl + 0 (iota 1000000))

  499999500000

  > t1

  #<timer:t1 0m 0.353s>

(with-timer timer expr ...)

Syntactic shorthand for:

  (profile timer (lambda () expr ...))

(timer-value timer)  number?
  timer : timer?

Returns the current value of timer. Timers are only updated when control passes into or out of a profile form.

(timer-reset! timer)  void?
  timer : timer?

Resets timer to zero.

(current-timer)  timer?

Returns the timer that is currently running.

(all-timers)  (listof timer?)

Returns a list of all timers created with make-timer or define-timer, plus a single predefined timer called 'top.

(define-timer id)

Syntactic shorthand for:

  (define id (make-timer 'id))