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

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

Thread Previous | Thread Next
From:
Benjamin Goldberg
Date:
September 4, 2001 01:42
Subject:
Re: Problem in ext/Time/HiRest/HiRes.t
Message ID:
3B94941C.8829E47B@earthlink.net
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();

To:

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About