Time::HiRes::Value - represent a time value or interval in exact microseconds
Time::HiRes::Value
The Time::HiRes module allows perl to access the system's clock to microsecond accuracy. However, floating point numbers are not suitable for manipulating such time values, as rounding errors creep in to calculations performed on floating-point representations of UNIX time. This class provides a solution to this problem, by storing the seconds and miliseconds in separate integer values, in an array. In this way, the value can remain exact, and no rounding errors result.
This function returns a new instance of a Time::HiRes::Value object. This object is immutable, and represents the time passed in to the $sec and $usec parameters.
$sec
$usec
If the $usec value is provided then the new Time::HiRes::Value object will store the values passed directly, which must both be integers. Negative values are represented in "additive" form; that is, a value of -1.5 seconds would be represented by
-1.5
Time::HiRes::Value->new( -2, 500000 );
If the $usec value is not provided, then the $sec value will be parsed as a decimal string, attempting to match out a decimal point to split seconds and microseconds. This method avoids rounding errors introduced by floating-point maths.
This function returns a new instance of Time::HiRes::Value containing the current system time, as returned by the system's gettimeofday() call.
gettimeofday()
Each of the methods here overloads an operator
This method returns a string representation of the time, in the form of a decimal string with 6 decimal places. For example
15.000000 -3.000000 4.235996
A leading - sign will be printed if the stored time is negative, and the $usec part will always contain 6 digits.
-
This method returns a new Time::HiRes::Value value, containing the sum of the passed values. If a string is passed, it will be parsed according to the same rules as for the new() constructor.
new()
Note that sum is provided as an alias to add.
sum
add
This method returns a new Time::HiRes::Value value, containing the difference of the passed values. If a string is passed, it will be parsed according to the same rules as for the new() constructor.
Note that diff is provided as an alias to sub.
diff
sub
This method returns a new Time::HiRes::Value value, containing the product of the passed values. $other must not itself be a Time::HiRes::Value object; it is an error to attempt to multiply two times together.
$other
This method returns a new Time::HiRes::Value value, containing the quotient of the passed values. $other must not itself be a Time::HiRes::Value object; it is an error for a time to be used as a divisor.
This method compares the two passed values, and returns a number that is positive, negative or zero, as per the usual rules for the <=> operator. If a string is passed, it will be parsed according to the same rules as for the new() constructor.
<=>
Time::HiRes - Obtain system timers in resolution greater than 1 second
Paul Evans <leonerd@leonerd.org.uk>
To install Time::HiRes::Value, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Time::HiRes::Value
CPAN shell
perl -MCPAN -e shell install Time::HiRes::Value
For more information on module installation, please visit the detailed CPAN module installation guide.