EV is an interface to the lower-level libev, and AFAIK it's fairly performant. Its "periodic" function claims to work with wall clock time, so you shouldn't have any drift relative to the system clock. That the system clock can drift relative to real time, and that it can be adjusted in jumps, are whole different issues. I'm not sure if the default ntpd supports smooth adjustments to the system clock (Update: apparently, it does), butand I believe chrony does. (I have several systems with a GPS receiver that supports the PPS signal, and I feed that into chronyd to provide a system time that should be quite accurate. I've published some info on that here.)

use warnings; use strict; use Math::BigFloat; use Time::HiRes qw/gettimeofday/; use EV; my $w1 = EV::signal( 'INT', sub { EV::break } ); my ($cnt, $avg, $prev) = (0); my $w2 = EV::periodic( 0, 1, 0, sub { my $cur = Math::BigFloat->new( sprintf("%d.%06d",gettimeofday) ); if ( defined $prev ) { my $delta = $cur - $prev; $avg = defined $avg ? ( $avg + $delta ) / 2.0 : $delta->copy; $cnt++; } $prev = $cur->copy; } ); EV::run; print "\nAverage over $cnt deltas: $avg\n";

Sample output from different runs on my system:

Average over 67 deltas: 1.000005597916695584862263807609389365538 Average over 76 deltas: 1.00012161307435464691799175142220832736 Average over 137 deltas: 0.9997675784785176200109895891945901313775 Average over 442 deltas: 0.9999437250604076389815434390305220372265

In reply to Re^3: The most precise second (timer) by haukex
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.