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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.