mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 21:59:17 +02:00
They can be close()d explicitly with close-file-descriptor, and will close() on gc, but only explicitly closing the last port on them will close the fileno. Notably needed for network sockets where we open separate input and output ports on the same socket.
30 lines
872 B
Scheme
30 lines
872 B
Scheme
|
|
(import (chibi time) (scheme cxr) (srfi 33) (srfi 39))
|
|
|
|
(define (timeval->milliseconds tv)
|
|
(quotient (+ (* 1000000 (timeval-seconds tv)) (timeval-microseconds tv))
|
|
1000))
|
|
|
|
(define (time* thunk)
|
|
(call-with-output-string
|
|
(lambda (out)
|
|
(let* ((start (car (get-time-of-day)))
|
|
(result (parameterize ((current-output-port out)) (thunk)))
|
|
(end (car (get-time-of-day)))
|
|
(msecs (- (timeval->milliseconds end)
|
|
(timeval->milliseconds start))))
|
|
(display "user: ")
|
|
(display msecs)
|
|
(display " system: 0")
|
|
(display " real: ")
|
|
(display msecs)
|
|
(display " gc: 0")
|
|
(newline)
|
|
(display "result: ")
|
|
(write result)
|
|
(newline)
|
|
result))))
|
|
|
|
(define-syntax time
|
|
(syntax-rules ()
|
|
((_ expr) (time* (lambda () expr)))))
|