mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-14 16:37:33 +02:00
Adding (time [<name>] <expr>) macro for easy benchmarking.
This commit is contained in:
parent
9dcf11056c
commit
87761001aa
1 changed files with 27 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
|
||||
(define-library (chibi time)
|
||||
(export current-seconds get-time-of-day
|
||||
(export current-seconds get-time-of-day time
|
||||
seconds->time seconds->string time->seconds time->string
|
||||
make-timeval make-tm timeval-seconds timeval-microseconds
|
||||
timezone-offset timezone-dst-time
|
||||
|
@ -19,4 +19,26 @@
|
|||
resource-usage/children get-resource-usage))
|
||||
(else))
|
||||
(import (chibi))
|
||||
(include-shared "time"))
|
||||
(include-shared "time")
|
||||
(begin
|
||||
(define (timeval->milliseconds tv)
|
||||
(quotient (+ (* 1000000 (timeval-seconds tv))
|
||||
(timeval-microseconds tv))
|
||||
1000))
|
||||
(define (time* name thunk)
|
||||
(let* ((start (car (get-time-of-day)))
|
||||
(result (thunk))
|
||||
(end (car (get-time-of-day)))
|
||||
(msecs (- (timeval->milliseconds end)
|
||||
(timeval->milliseconds start))))
|
||||
(display name (current-error-port))
|
||||
(display ": " (current-error-port))
|
||||
(display msecs (current-error-port))
|
||||
(display " ms\n" (current-error-port))
|
||||
result))
|
||||
(define-syntax time
|
||||
(syntax-rules ()
|
||||
((time expr)
|
||||
(time (call-with-output-string (lambda (out) (write expr out))) expr))
|
||||
((time name expr)
|
||||
(time* name (lambda () expr)))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue