Is there an equivalent to Lisp's "runtime" primitive in Scheme?
current-milliseconds
is a function that returns the current millisecond count from the system, but it might decrease. current-inexact-milliseconds
is similar, but returns a guaranteed-to-increase floating point number.
There are also a bunch of similar functions that you can find on that page, but if all you need is to time a certain function, then just use (time
expr) and it will print out the time it took to evaluate the expression.
Another thing that is relevant here is the profiler, in case you need some more verbose analysis of your code.
I too came across this problem today. I am using DrRacket, as it seems to have superseded DrScheme. Though this is an old thread, I am adding my findings for anyone new who stumbles across this thread.
With R5RS (#lang r5rs
) as selected language, add following two lines before the program to make it work
(#%require (only racket/base current-milliseconds))
(define (runtime) (current-milliseconds))
You can use the package sicp that contains definition of the runtime
.
Here is the package description.
And here is the installation instructions:
Open the Package Manager: in DrRacket choose the menu File then choose Package Manager….
In the tab Do What I Mean find the text field and enter:
sicp
Finally click the Install button.
Now you can call runtime
and other procedures from SICP:
#lang sicp
(runtime)
An expected output would be like this:
1606611898030115
>