Search code examples
lispschemeracketsicp

SICP, Scheme, DrRacket Question: Timer/profiler function?


I'm currently trying to do exercise 1.22, which needs a function called runtime that returns the number of milliseconds the system has been running. However, my environment (R5RS) does not seem to have this. It does not have time, current-milliseconds, current-inexact-milliseconds, etc, either.

What function do I have access to, to profile my function? Which functions returns the number of milliseconds, microseconds, etc, that have passed? I would of course prefer the highest precision timer available.


Solution

  • Probably, the best thing to do is switch the language in DrRacket to "Use the language declared in the source", and start your file with #lang racket. Then functions like current-seconds and friends will be available.

    Alternatively, you could use the profiling library, available via (require profile) and documented here.

    Finally, you might want to look at Neil Van Dyke's SICP library for DrRacket.