[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
(ice-9 time)
From: |
Marius Vollmer |
Subject: |
(ice-9 time) |
Date: |
21 Mar 2001 01:21:28 +0100 |
User-agent: |
Gnus/5.0803 (Gnus v5.8.3) Emacs/20.7 |
Hi,
why did you write `time' as a macro? It does not actually expand into
code, but performs the action itself. This will make it fail with a
compiler. (It doesn't matter in the repl, but `time' can easily be of
broader use.)
Also, it does use `eval' which I find counter-intuitive. (Because of
`eval', you can't really time code in a lexical environment.)
I would have written it like this:
(define (time-proc proc)
(let* ((gc-start (gc-run-time))
(tms-start (times))
(result (proc))
(tms-end (times))
(gc-end (gc-run-time)))
(define (get proc start end)
(/ (- (proc end) (proc start)) internal-time-units-per-second))
(display "clock utime stime cutime cstime gctime\n")
(format #t "~5,2F ~5,2F ~5,2F ~6,2F ~6,2F ~6,2F\n"
(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 id gc-start gc-end))
result))
(define-macro (time exp)
(time-proc (lambda () ,@exp)))
What do you think?
- (ice-9 time),
Marius Vollmer <=