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

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

Thread Previous | Thread Next
From:
John P. Linderman
Date:
August 31, 2001 03:27
Subject:
Re: Problem in ext/Time/HiRest/HiRes.t
Message ID:
200108311027.GAA07020@raptor.research.att.com
> 
> 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)
> 
> -- 
> Arthur
> 

I think it's risky to assume that your process won't get swapped
out for a second or two between the time() and the Time::HiRes::time().
Maybe something like

my $t1 = time();
my $tf = Time::HiRes::time();
my $t2 = 1 + time();

and confirm that ($t1 <= $tf) && ($tf <= $t2)

One might even try a few iterations, ($t2 - $t1) is greater than 1.
--jpl


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