Move timing out into a separate module

This commit is contained in:
Oliver Payne 2023-11-04 21:13:32 +00:00
parent a16df8cca2
commit fd1d3682f3
3 changed files with 24 additions and 17 deletions

View File

@ -6,7 +6,8 @@
"syntax.rkt"
"environment.rkt"
"common.rkt"
"special-forms.rkt")
"special-forms.rkt"
"timing.rkt")
(#%provide ambeval
driver-loop)

View File

@ -5,26 +5,12 @@
(#%require "dd-mceval.rkt"
"analyzing-mceval.rkt"
"leval.rkt")
"leval.rkt"
"timing.rkt")
(#%require (only racket current-process-milliseconds))
(#%require (only racket/base module+))
;; 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)))))
(define (fact-program x)
`((define (fact n)
(if (= n 1) 1

20
mceval/timing.rkt Normal file
View File

@ -0,0 +1,20 @@
#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)))))