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"; }
In reply to Re^5: The most precise second (timer)
by haukex
in thread The most precise second (timer)
by tukusejssirs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |