Unfortunately this is not necessarily true. My tests on FreeBSD show that times() does not return a monotonically increasing value.
Setting the time back two minutes:
now(1060100580.89445) - then(1060100701.61873) = diff(-120.724280953407)
( clk_now(-1746079118) - clk_then(-1746063665) ) / CLOCKS_PER_SEC = -120.7265625
"now" and "then" being time() values, while "clk_now" and "clk_then" are
POSIX::times() values.
Are there any other sources of monotonic time available to Perl?
-- Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org
Apparently, this is an artifact of its FreeBSD implementation. You may want to post on the related newsgroups.
Here are some of my findings, and a description of how I reached the conclusion that this is a FreeBSD issue.
Originally, I was somewhat alarmed (no pun intended) by the negative value of (POSIX::times())[0]. A closer look of the man page indicated that it's possible to get an overflow in the returned value (enclosed is an extract of the man page). I also verified that on MacOS X, indeed that value could be negative. However, I did find something odd:
-1746079118 - (-1746063665) = -15453 This means CLOCKS_PER_SEC = -15453/-120.7265625 = 128
CLOCKS_PER_SEC is 128!? That sounded fishy. So I began to wonder whether there was something about the particular implementation. Searching on google with the keywords, "POSIX times FreeBSD" turned up the following post. The post is in russian, but the included man page is in English.
http://groups.google.com/ groups?q=POSIX+times+FreeBSD&start=20&hl=en&lr=&ie=UTF-8&oe=UTF- 8&selm=1037625558%40f500.n5030.z2.ftn&rnum=26
You may notice that according to the man page, the value returned by (POSIX::times)[0] actually came from gettimeofday. There is little wonder that it is not monotonically increasing.
FreeBSD is not alone in this. I found a similar anomaly on MacOSX which has a CLOCKS_PER_SEC of 100, and (POSIX::times)[0] is not monotonically increasing either. It appears that this may be a wide spread issue w/ various BSD derivatives.
FreeBSD Miscellaneous Information Manual CLOCKS(7)
NAME
clocks - various system timersSYNOPSIS
#include <time.h>...
The clock reported by times (3). This is a virtual clock with a fre-
quency that happens to be 128. Its actual frequency is given by the
macro CLK_TCK (deprecated; do not use) and by sysconf(SC_CLK_TCK) and
by sysctl(3). Note that its frequency may be different from
CLOCKS_PER_SEC. Do not use times (3) in new programs under FreeBSD .
It is feeble compared with gettimeofday(2) together with
getrusage(2). It is provided for POSIX conformance. It is imple-
mented by calling gettimeofday(2) and getrusage(2) and throwing away
information and resolution.
TIMES(2) Linux Programmer's Manual TIMES(2)
NAME times - get process times
SYNOPSIS #include <sys/times.h>
clock_t times(struct tms *buf); ...
RETURN VALUE
The function times returns the number of clock ticks that
have elapsed since an arbitrary point in the past. For
Linux this point is the moment the system was booted.
This return value may overflow the possible range of type
clock_t. On error, (clock_t) -1 is returned, and errno is
set appropriately.Pete
