views:

75

answers:

2

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.

A: 

I used current-inexact-milliseconds when I did that exercise. Spoiler Alert: You can see my solution on my blog at SICP Exercise 1.22: Timed Prime Test.

By the way, I only solved that problem after asking a similar question, Is there an equivalent to Lisp's “runtime” primitive in Scheme?

Bill the Lizard
As I stated in my post, current-inexact-milliseconds does NOT work. I get the following error: reference to undefined identifier: current-inexact-milliseconds. What environment are you using?
KnowsLittle
@KnowsLittle: I run DrScheme with the Language "Module" selected to do the SICP exercises. Sorry, I thought I had mentioned that in the linked article. I'll need to update that.
Bill the Lizard
+2  A: 

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.

Sam TH