|
From: | Lassi Kortela |
Subject: | Re: Exposing subsecond precision in current-seconds |
Date: | Mon, 27 Apr 2020 21:57:18 +0300 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
Sorry, I meant to write microseconds.
No problem. In that case, please take a look at Gambit's time API: <https://www.iro.umontreal.ca/~gambit/doc/gambit.html#Measuring-time>. It uses a float for the internal representation of time objects. `time->seconds` extracts it an ordinary float out of it. Perhaps the same interface could be used in Chicken.
For nanoseconds precision you'd need to use `clock_gettime` which is harder to emulate on Windows than `gettimeofday`.
The main point of nanosecond precision in Scheme is to preserve bit-for-bit precise timestamps from Unix file system APIs (in case you copy the timestamp elsewhere and somebody later compares it for exact equality with the original). NTFS timestamps have 100-nsec precision, so a (seconds nanoseconds) pair is good for them as well.
It's unlikely that useful ns-level accuracy for the current time is obtainable in any Scheme program (or any program generally). System call overhead is measured in microseconds. I guess CPU cycle counters in theory have nanosecond accuracy, but those are useful mainly in computing the time elapsed between two counters, not in reference to exact moments on a standard timescale like UTC.
[Prev in Thread] | Current Thread | [Next in Thread] |