Subject: Re: Displaying current time/date
From: rpw3@rigden.engr.sgi.com (Rob Warnock)
Date: 1999/11/17
Newsgroups: comp.lang.scheme
Message-ID: <80u499$1c12q@fido.engr.sgi.com>
Paulo Jorge De Oliveira Cantante De Matos  <pocm@rnl.ist.utl.pt> 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
	35
	> 

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)
		        (time-apply
			  (lambda ()
			    (expt 2 10000)
			    (values 'all 'done 'now)))))
	    (for-each display (list "result: " v ", cpu: " c ", real: " r))
	    (newline))
	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:

	<URL:http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node135.htm>
	<URL:http://www.cs.rice.edu/CS/PLT/packages/doc/mzscheme/node134.htm>

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


-Rob

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