in reply to Re^4: The most precise second (timer)
in thread The most precise second (timer)
nanosleep (1000000000);
I think that with a fixed time like that, you'll probably still see a cumulative error if you run it for a longer time, I don't think 5 minutes is enough.
However, I only now realized that I overlooked a solution that should have been staring me in the face: clock_nanosleep(2), which is also provided by Time::HiRes. Try running the following over a longer time (several hours):
use warnings; use strict; use Time::HiRes qw/ clock_gettime clock_nanosleep CLOCK_REALTIME TIMER_ABSTIME /; die "Don't have nanosleep" unless Time::HiRes::d_nanosleep(); my $run = 1; $SIG{INT} = sub { $run = 0 }; while ($run) { my $now_s = int(clock_gettime(CLOCK_REALTIME)); clock_nanosleep(CLOCK_REALTIME, ($now_s+1)*1e9, TIMER_ABSTIME); last unless $run; print clock_gettime(CLOCK_REALTIME), "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: The most precise second (timer)
by tukusejssirs (Beadle) on Nov 28, 2019 at 11:33 UTC |