Closed sjakobi closed 5 years ago
It seems both clock
and GHC
are using exactly the same system call i.e. clock_gettime
with a CLOCK_MONOTONIC
clock type to get the time.
The difference may be due to the setup code to get the results. The clock
package allocates memory using alloca
:
getTime clk = allocaAndPeek $! clock_gettime $! clockToConst clk
While GHC is using StgWord64:
StgWord64 getMonotonicNSec(void)
{
#if defined(HAVE_CLOCK_GETTIME)
struct timespec ts;
int res;
res = clock_gettime(CLOCK_ID, &ts);
if (res != 0) {
sysErrorBelch("clock_gettime");
stg_exit(EXIT_FAILURE);
}
return (StgWord64)ts.tv_sec * 1000000000 +
(StgWord64)ts.tv_nsec;
StgWord64
may be more efficient than alloca
. Though, it should make any practical difference only if we use the getTime
call very very often.
Sample results from my machine: