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)
|
(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
|
seconds->time seconds->string time->seconds time->string
|
||||||
make-timeval make-tm timeval-seconds timeval-microseconds
|
make-timeval make-tm timeval-seconds timeval-microseconds
|
||||||
timezone-offset timezone-dst-time
|
timezone-offset timezone-dst-time
|
||||||
|
@ -9,9 +9,9 @@
|
||||||
time-offset
|
time-offset
|
||||||
tm? timeval? timezone?)
|
tm? timeval? timezone?)
|
||||||
(cond-expand
|
(cond-expand
|
||||||
(emscripten)
|
(emscripten)
|
||||||
(else
|
(else
|
||||||
(export set-time-of-day!)))
|
(export set-time-of-day!)))
|
||||||
(cond-expand
|
(cond-expand
|
||||||
((or bsd linux)
|
((or bsd linux)
|
||||||
(export rusage? resource-usage-time resource-usage-system-time
|
(export rusage? resource-usage-time resource-usage-system-time
|
||||||
|
@ -19,4 +19,26 @@
|
||||||
resource-usage/children get-resource-usage))
|
resource-usage/children get-resource-usage))
|
||||||
(else))
|
(else))
|
||||||
(import (chibi))
|
(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