Okay, I your point with the fixed times.

I like the way you made the clock_nanosleep(CLOCK_REALTIME, ($now_s+1)*1e9, TIMER_ABSTIME);. In short tests (like for 10-20 s), the average diff is always 1.00000000000000000000, at least with the 5 decimal places the clock_gettime(CLOCK_REALTIME) outputs.

Anyway, I am in the middle of 5 h run of the script; I’ll report the results when it is finished.

Again, thanks for your time!

Update: I have found out (using printf) that 0001511573791503906250 printf ("%.40f\n\n", clock_gettime(CLOCK_REALTIME)); outputs floats with 21 to 22 decimal places, therefore I’ll print the time out using printf ("%.22f\n", clock_gettime(CLOCK_REALTIME));. This might slow the execution of the script and thus the measurement won’t be that accurate. Or even worse: the extra time (decimal places) are only the time required to execute the extra stuff, I don’t know.

Update 2: I have the results of the 5-hour run of your script. I have calculated the difference as follows, but my calculations might be wrong, therefore here is the list of 18,000 time values. Note that the machine was not running only this script, because the timer (periodic runner) won’t be run as the only program on the server in production.

average diff between times : +0.999999998888827179577276638156035915 +0171 average diff from second : +0.000000001111172842935718417798556472 +2552

This is quite nice. I has already surpassed my assumptions. I’ve read the Time::HiRes readme, so I do not expect clock_nanosleep() to be exact down to one nanosecond, but the average results above tells me that that it is as least _nearly_ that accurate (at least on my system and its configuration).

hawkex, I can’t thank you enough! You’re great!


In reply to Re^6: The most precise second (timer) by tukusejssirs
in thread The most precise second (timer) by tukusejssirs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.