Search code examples
sicpchicken-scheme

In CHICKEN Scheme, how does one get unix time?


I'm looking for a way to get unix time in CHICKEN Scheme, or any other timestamp for that matter, which I can compare like it's a number with other timestamps.

I want this because I'm trying to emulate (runtime) which is defined in the book I'm reading (SICP) as "the time since starting the interpreter", but because we are just looking for differences between these stamps at different points, it doesn't really matter.

I could go into more detail if that helps: I'm trying to do exercise 1.22.


Solution

  • There's (current-seconds) from the chicken module, which gives you the current UNIX timestamp.

    With (current-milliseconds), which is also from the chicken module, you can get the number of milliseconds that have passed since the process was started.

    Of course you're building this in the exercise yourself, but in real world cases you probably want to just use the (time) special form, which gives you detailed information about the running time of an algorithm, including GC information.