21 lines
500 B
Racket
21 lines
500 B
Racket
#lang sicp
|
|
|
|
(#%require (only racket current-process-milliseconds))
|
|
|
|
(#%provide time-proc)
|
|
|
|
;; Call proc on args n times and output the average time per run
|
|
(define time-proc
|
|
(lambda (iterations proc)
|
|
(let ((start-time (current-process-milliseconds)))
|
|
(let loop ((n iterations))
|
|
(if (> n 0)
|
|
(begin
|
|
(proc)
|
|
(loop (- n 1)))))
|
|
(exact->inexact
|
|
(/ (- (current-process-milliseconds)
|
|
start-time)
|
|
iterations)))))
|
|
|