Re: why I cannot stop this loop at 50 points? (code)



blargg.ei3@xxxxxxxxxxxxx (blargg) writes:

Keith Thompson <kst-u@xxxxxxx> wrote:
lawrence.jones@xxxxxxxxxxx writes:
James Dow Allen <jdallen2000@xxxxxxxxx> wrote:
Why not
find the hypothetical library that makes time() a
float and stamp it out:

It's not hypothetical: SAS/C for the IBM mainframe implements time_t as
double. (The system time-of-day clock has subsecond resolution, so it
makes some sense to expose that to C programs.)
[...]
One obvious disadvantage is that the resolution varies over time. For
times sufficiently close to the epoch, you can distinguish between one
yottasecond and the next. By now, the resolution (given FLT_RADIX ==
16 and DBL_MANT_DIG == 14, thus 56 bits of precision) is around 3.7
nanoseconds, and it will remain there for some time. If that's finer
than the resolution of the system time-of-day clock, I suppose that's
not a real problem. But I still think it would have been better to
use a large integer representing, say, a number of nanoseconds.

How is that much different than say using a nanosecond timebase and
dividing that value by 1e-9? Either way, once the time value gets
sufficiently large, you get less and less than nanosecond
resolution.

Yes, but you are not forced to divide by 1e9. For example if you
subtract two times you get nanosecond resolution for years to come. A
floating time (or two integer nansecond times divided by 1e9) slowly
loses resolution as time goes by.

And if you do need to divide, having the integer version lets you
decide how to do that. You could use a wider floating type, or an
arbitrary precision maths library. A constant resolution integer time
is simply a better design.

--
Ben.
.



Relevant Pages

  • Re: alternative to gettickcount
    ... And how does your VB code know what the CPU clock frequency is on the machine on which it is running, so that it knows how to interpret the result? ... Let's face it, Ulrich, ther is NO WAY that you are going to get a nanosecond resolution out of timing anything on a pc! ...
    (microsoft.public.vb.general.discussion)
  • Re: alternative to gettickcount
    ... VB code timing results in the "sub nanosecond" order, ... Ulrich has claimed he is able to do. ... "The resolution is below one nanosecond. ...
    (microsoft.public.vb.general.discussion)
  • Re: why I cannot stop this loop at 50 points? (code)
    ... (The system time-of-day clock has subsecond resolution, ... use a large integer representing, say, a number of nanoseconds. ... but you are not forced to divide by 1e9. ... You could use a wider floating type, ...
    (comp.lang.c)
  • Re: alternative to gettickcount
    ... give you one nanosecond resolution in any meaningful way. ... You need to couple QueryPerformanceCounter with QueryPerformanceFrequency for it to have any real meaning. ... But when QPC was polled in a tight loop, ... involves at least one "travel across the bridge" and which therefore cannot possibly produce a result anywhere near the one nanosecond that you have postulated. ...
    (microsoft.public.vb.general.discussion)
  • Re: utime() vs. utimes()
    ... I get nanosecond mtime resolution on Solaris, for instance, by peeking into the stat struct. ... The Solaris stat structure stores nanosecond resolution; it doesn't matter what the underlying FS can do as long as it's not finer-grained than nanosecond. ...
    (comp.unix.programmer)