Closed arthurmaciel closed 3 years ago
@arthurmaciel Thanks for the pull request. I don't remember why the code used gettimeofday instead of clock_gettime, but from what I can tell there is no good reason not to switch. Let me get this merged in later tonight.
Regarding bignums, I would prefer to keep returning a double to keep the overhead down. That said, bignums would probably not incur a major hit to performance. How critical is it to add the extra precision? It could make sense to have a benchmark loop several times, as the r7rs benchmarks do, in which case the results may ultimately be on the order of seconds, or only a handful of decimal places.
@justinethier, thanks for the answer. Following your recommendations I have proposed #452 to change core code to use clock_gettime().
Now we have a very simple benchmark package that returns seconds with up to 9 decimal places (nanoseconds). We can keep R7RS
orientation to return an exact integer with (current-jiffy)
, but gain more precision with the new library, if needed.
@justinethier, for more precision, may I change
current-jiffy
to return nanoseconds (in a bignum) instead of microseconds as is now? Is the bignum allocation a significant slow down?Independently of using
gettimeofday
orclock_gettime
, should we have a failsafe implementation for more restricted platforms? I am not sure which platforms Cyclone targets.I am fiddling with this because I need a simple benchmark library. I have checked that both Python and Julia use
clock_gettime
and return the number of seconds as a double with up to 9 decimal points (nanoseconds). But our specification demands the return of an exact integer.R7RS just for reference:
(current-jiffy)
time library procedure Returns the number of jiffies as an exact integer that have elapsed since an arbitrary, implementation-defined epoch. A jiffy is an implementation-defined fraction of a second which is defined by the return value of thejiffies-per-second
procedure. The starting epoch is guaranteed to be constant during a run of the program, but may vary between runs.Rationale: Jiffies are allowed to be implementation-dependent so that
current-jiffy
can execute with minimum overhead. It should be very likely that a compactly represented integer will suffice as the returned value. Any particular jiffy size will be inappropriate for some implementations: a microsecond is toolong for a very fast machine, while a much smaller unit would force many implementations to return integers which have to be allocated for most calls, renderingcurrent-jiffy
less useful for accurate timing measurements.