ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/EV/t/01_timer.t
(Generate patch)

Comparing EV/t/01_timer.t (file contents):
Revision 1.3 by root, Sat Nov 17 01:48:49 2007 UTC vs.
Revision 1.6 by root, Thu Nov 22 04:52:24 2007 UTC

1BEGIN { $| = 1; print "1..6002\n"; } 1BEGIN { $| = 1; print "1..6002\n"; }
2 2
3no warnings; 3no warnings;
4use strict;
4 5
5use EV; 6use EV;
7
8my $fudge = 0.02; # allow rt and monotonic clock to disagree by this much
6 9
7my $id = 1; 10my $id = 1;
8my @timer; 11my @timer;
9my @periodic; 12my @periodic;
10 13
11my $base = EV::now; 14my $base = EV::now;
12my $prev = EV::now; 15my $prev = EV::now;
13 16
14for (1..1000) { 17for my $i (1..1000) {
15 my $t = $_ * $_ * 1.735435336; $t -= int $t; 18 my $t = $i * $i * 1.735435336; $t -= int $t;
16 push @timer, EV::timer $t, 0, sub { 19 push @timer, EV::timer $t, 0, sub {
17 my $now = EV::now; 20 my $now = EV::now;
18 21
19 print $now >= $prev ? "" : "not ", "ok ", ++$id, " # t0 $now >= $prev\n"; 22 print $now + $fudge >= $prev ? "" : "not ", "ok ", ++$id, " # t0 $i $now + $fudge >= $prev\n";
20 print $now >= $base + $t ? "" : "not ", "ok ", ++$id, " # t1 $now >= $base + $t\n"; 23 print $now + $fudge >= $base + $t ? "" : "not ", "ok ", ++$id, " # t1 $i $now + $fudge >= $base + $t\n";
21 24
22 unless ($id % 3) { 25 unless ($id % 3) {
23 $t *= 0.0625; 26 $t *= 0.0625;
24 $_[0]->set ($t); 27 $_[0]->set ($t);
25 $_[0]->start; 28 $_[0]->start;
27 } 30 }
28 31
29 $prev = $now; 32 $prev = $now;
30 }; 33 };
31 34
32 my $t = $_ * $_ * 1.375475771; $t -= int $t; 35 my $t = $i * $i * 1.375475771; $t -= int $t;
33 push @periodic, EV::periodic $base + $t, 0, 0, sub { 36 push @periodic, EV::periodic $base + $t, 0, 0, sub {
34 my $now = EV::now; 37 my $now = EV::now;
35 38
36 print $now >= $prev ? "" : "not ", "ok ", ++$id, " # p0 $now >= $prev\n"; 39 print $now >= $prev ? "" : "not ", "ok ", ++$id, " # p0 $i $now >= $prev\n";
37 print $now >= $base + $t ? "" : "not ", "ok ", ++$id, " # p1 $now >= $base + $t\n"; 40 print $now >= $base + $t ? "" : "not ", "ok ", ++$id, " # p1 $i $now >= $base + $t\n";
38 41
39 unless ($id % 3) { 42 unless ($id % 3) {
40 $t *= 1.0625; 43 $t *= 1.0625;
41 $_[0]->set ($base + $t); 44 $_[0]->set ($base + $t);
42 $_[0]->start; 45 $_[0]->start;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines