use Time::Monotonic qw(monotonic_time); $t1 = monotonic_time(); sleep(1); $t2 = monotonic_time(); die unless Time::Monotonic::is_monotonic(); say "Backend API: ".Time::Monotonic::backend();
Time::Monotonic gives access to monotonic clocks on various platforms (Mac OS X, Windows, and POSIX). A monotonic clock is a time source that won't ever jump forward or backward (due to NTP or Daylight Savings Time updates).
Time::Monotonic uses Thomas Habets's cross platform "monotonic_clock" library under the hood.
monotonic_time()
This function returns a monotonic time as a floating point number (fractional seconds). Note that this time will not be comparable to times from the built-in time function. The only real use of the value is comparing against other values returned from monotonic_time().
time
backend()
This function returns which backend clock functions are in use. It will be one of:
'clock_gettime'
'mach_absolute_time'
'QueryPerformanceCounter'
'generic'
is_monotonic()
This will return true if the backend supports monotonic clocks. This can return false if there is no support for monotonic clocks in the current Platform/OS/hardware combo.
Source Code Repository
Why are monotonic clocks important?
monotonic_clock library
David Caldwell <david@porkrind.org>
Copyright (C) 2015 by David Caldwell
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.4 or, at your option, any later version of Perl 5 you may have available.
To install Time::Monotonic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Time::Monotonic
CPAN shell
perl -MCPAN -e shell install Time::Monotonic
For more information on module installation, please visit the detailed CPAN module installation guide.