I don't think trying to bracket the hires time with lores
authorJarkko Hietaniemi <jhi@iki.fi>
Sun, 25 Nov 2001 19:11:38 +0000 (19:11 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Sun, 25 Nov 2001 19:11:38 +0000 (19:11 +0000)
times is going to be portable enough: Cygwin seems to be
capable of getting hires ones rather consistently lower
than the lores ones.  So let's try average difference instead.

p4raw-id: //depot/perl@13266

ext/Time/HiRes/HiRes.t

index bee3257..ad0dcc3 100644 (file)
@@ -133,16 +133,15 @@ else {
 if (!$have_time) {
     skip 14
 } else {
- my ($t1, $tf, $t2);
- for my $i (1 .. 20) {
-     $t1 = time();
-     $tf = Time::HiRes::time();
-     $t2 = 1 + time();
-     last if (($t2 - $t1) <= 1) && $t1 <= $tf;
+ my ($s, $n);
+ for my $i (1 .. 100) {
+     $s += Time::HiRes::time() - time();
+     $n++;
  }
- ok 14, (($t1 <= $tf) && ($tf <= $t2)),
-      "Time::HiRes::time $tf not bracketed by [$t1, $t2]";
-
+ # $s should be, at worst, equal to $n
+ # (time() may be rounding down, up, or closest)
+ ok 14, abs($s) / $n <= 1.0, "Time::HiRes::time() not close to time()";
+ print "# s = $s, n = $n, s/n = ", $s/$n, "\n";
 }
 
 unless (defined &Time::HiRes::gettimeofday