This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

time macro


Hello,

Since this doesn't seem to be included in the core, I have written
a tiny time macro which works like this:

  guile> (time (use-modules (oop goops)))
  clock utime stime cutime cstime gc
  0.29  0.28  0.01  0      0      0.16

Thanks,
Keisuke Nishida

;; time.scm

(define-module (help time)
  :use-module (ice-9 format))

(define unit
  (let ((start (times)))
    (sleep 1)
    (/ 1.0 (- (tms:clock (times)) (tms:clock start) 1))))

(export time)
(define-macro (time form)
  `(let ((tms-start (times))
	 (gc-start (gc-run-time))
	 (result ,form)
	 (tms-end (times))
	 (gc-end (gc-run-time))
	 (get (lambda (proc start end)
		(* (- (proc end) (proc start)) ,unit))))
     (display "clock utime stime cutime cstime gc\n")
     (format #t "~5a ~5a ~5a ~6a ~6a ~a~%"
	     (get tms:clock tms-start tms-end)
	     (get tms:utime tms-start tms-end)
	     (get tms:stime tms-start tms-end)
	     (get tms:cutime tms-start tms-end)
	     (get tms:cstime tms-start tms-end)
	     (get (lambda (x) x) gc-start gc-end))
     result))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]