main.scm 523 B

123456789101112131415161718
  1. (use-modules (srfi srfi-19))
  2. (define-module (myutil time)
  3. #:export (time))
  4. (define-syntax time
  5. (syntax-rules ()
  6. [(time expr expr* ...)
  7. (begin
  8. (define start-time (current-time time-monotonic))
  9. expr
  10. expr* ...
  11. (define end-time (current-time time-monotonic))
  12. (let* ([diff (time-difference end-time start-time)]
  13. [elapsed-ns (+ (/ (time-nanosecond diff) 1e9)
  14. (time-second diff))])
  15. (display (format #f "~fs~%" elapsed-ns))))]))