Subject: Re: Displaying current time/date
From: (Rob Warnock)
Date: 1999/11/17
Newsgroups: comp.lang.scheme
Message-ID: <80u499$>
Paulo Jorge De Oliveira Cantante De Matos  <> wrote:
| > (define d (seconds->date (current-seconds)))
| With the commands you told me, I think I-ll be able to define a start-time,
| an end-time and subtract it to know the time a procedure lasted. What do
| you think?  Is it a good was to implement the time it taked the procedure
| to compute something?

At the top-level REPL, MzScheme supports (as do many others) the "time"
macro (or special form or syntax), which takes an unevaluated form,
evaluates it (saving the value) while measuring the time, prints the
timing results to the terminal [in MzScheme's case, in milliseconds],
then returns the value:

	> (+ 12 (time (begin (expt 2 10000) 23)))
	cpu time: 28 real time: 29 gc time: 0

That's fine for interactive experimentation, but if you're trying
to do multiple timings in a benchmark or batch script, MzScheme's
"(time-apply <thunk>)" is probably better, since it print nothing,
instead returning three values: a list containing the result(s) of
calling the thunk, the CPU msecs, and the real-time msecs, e.g.:

	> (let-values (((v c r)
			  (lambda ()
			    (expt 2 10000)
			    (values 'all 'done 'now)))))
	    (for-each display (list "result: " v ", cpu: " c ", real: " r))
	result: (all done now), cpu: 29, real: 29

[Obviously, you could have done something else with v/c/r other than
just print them...]

For more on these MzScheme features and others such as
(current-milliseconds), (current-process-milliseconds), and
(current-gc-milliseconds) [which can be used to roll your own
"time-apply", if you don't like the built-in one], see:


Also look at other implementations' documentation. Almost all implementations
have some more-or-less equivalent set of features (though almost all are


Rob Warnock, 8L-846
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA