#=
Using immutable rather than type with fields that are
simple and immediate values keeps information directly
available (rather than indirectly available, like arrays).
Use Int64 because nanosecond timing uses 64 bits (UInt64).
time_ns() "Get the time in nanoseconds.
The time corresponding to 0 is undefined,
and wraps every 5.8 years."
time_zero because the timer is given as a UInt64 value, and
there are more of those than positive Int64s.
=#
const time_zero = [time_ns()]
get_time_zero() = time_zero[1]
function set_time_zero(nanoseconds::UInt64)
time_zero[1] = nanoseconds
return nanoseconds
end
immutable FineComputerTime
seconds::Int64
nanoseconds::Int64
end
function FineComputerTime(nanosecs::UInt64)
nanosecs -= get_time_zero()
secs, nsecs = fldmod( nanosecs, 1_000_000_000%UInt64 ) # value%UInt64 is a fast way to force the type
return FineComputerTime( Int64(secs), Int64(nsecs) )
end
FineComputerTime() = FineComputerTime(time_ns())