develooper Front page | perl.perl5.porters | Postings from September 2001

Re: Problem in ext/Time/HiRest/HiRes.t

Thread Previous | Thread Next
Benjamin Goldberg
September 4, 2001 01:42
Re: Problem in ext/Time/HiRest/HiRes.t
Message ID:
Arthur Bergman wrote:
> Test 14 is the following.
> my $t = time();
> my $tf = Time::HiRes::time();
> ok 14, (abs($tf - $t) <= 1),
> "time $t differs from Time::HiRes::time $tf";
> When run this multiple (several thousand) times I end up with the
> following.
> time 999252194 differs from Time::HiRes::time 999252195.000034
> I think the intent would be
> ok 14, (int($tf - $t) <= 1),
> "time $t differs from Time::HiRes::time $tf";
> If anyone either opposes this or feels tempted to rewrite the test
> chime in or I will change it. (this explains a random failing in the
> Linux smokes)

ISTM that the test [with the abs] is correct as is.  The test is doing
what it's meant to do, -- checking that the difference between the
builtin time() and the hires time() is less than or equal to one second.
The problem is that it was designed with the idea that both assignments
would be exactly simultaneously, and they're not.

With that in mind, try changing the code from:

my $t = time();
my $tf = Time::HiRes::time();


my $tf = Time::HiRes::time();
my $t = time();

And say if you have any different results.  [Leave the abs() as is]

"I think not," said Descartes, and promptly disappeared.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About