ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Coro/eg/bench
(Generate patch)

Comparing cvsroot/Coro/eg/bench (file contents):
Revision 1.7 by root, Sat Jul 21 19:53:29 2001 UTC vs.
Revision 1.12 by root, Fri Nov 24 15:34:33 2006 UTC

5# how fast it is, this little proggie compares a normal subroutine 5# how fast it is, this little proggie compares a normal subroutine
6# call with two calls of transfer in a loop. 6# call with two calls of transfer in a loop.
7 7
8use Coro; 8use Coro;
9use Benchmark; 9use Benchmark;
10
11sub a($) { }
10 12
11$a = bless {}, main::; 13$a = bless {}, main::;
12 14
13sub b { 15sub b {
14 my ($self) = shift; 16 my ($self) = shift;
17} 19}
18 20
19$b = async { 21$b = async {
20 # do a little unrolling... 22 # do a little unrolling...
21 while() { 23 while() {
22 yield; yield; yield; yield; yield; 24 cede; cede; cede; cede; cede;
23 } 25 }
24}; 26};
25 27
26yield; 28cede;
27 29
28$main = $Coro::main; 30$main = $Coro::main;
29 31
30*transfer = \&Coro::State::transfer; 32*transfer = \&Coro::State::transfer;
31 33
32sub doit { 34sub doit0 {
33 while() { 35 while() {
34 # some unrolling here as well.. 36 # some unrolling here as well..
35 transfer($c, $main); transfer($c, $main); 37 transfer($c0, $main, 0); transfer($c0, $main, 0);
36 transfer($c, $main); transfer($c, $main); 38 transfer($c0, $main, 0); transfer($c0, $main, 0);
37 transfer($c, $main); transfer($c, $main); 39 transfer($c0, $main, 0); transfer($c0, $main, 0);
40 transfer($c0, $main, 0); transfer($c0, $main, 0);
38 } 41 }
39} 42}
40 43
41$c = Coro::State::_newprocess [sub { 44sub doit1 {
42 doit(1,2,3,4,5,6,7,8,9); 45 while() {
43}]; 46 # some unrolling here as well..
47 transfer($c1, $main, -1); transfer($c1, $main, -1);
48 transfer($c1, $main, -1); transfer($c1, $main, -1);
49 transfer($c1, $main, -1); transfer($c1, $main, -1);
50 transfer($c1, $main, -1); transfer($c1, $main, -1);
51 }
52}
44 53
45transfer($main, $c); 54$c0 = new Coro::State sub {
46 55 doit0(1,2,3,4,5,6,7,8,9);
47timethese 100000, {
48 empty => '&a; &a',
49 method => '$a->b(5); $a->b(6)',
50 yield => 'yield',
51 transfer => 'transfer($main, $c)',
52}; 56};
53 57
58$c1 = new Coro::State sub {
59 doit1(1,2,3,4,5,6,7,8,9);
60};
61
62transfer($main, $c0, 0);
63transfer($main, $c1, -1);
64
65timethese 1000000, {
66 function => 'a(5); a(6)',
67 method => '$a->b(5); $a->b(6)',
68 cede => 'cede',
69 transfer0 => 'transfer($main, $c0, 0)',
70 transfer1 => 'transfer($main, $c1, -1)',
71};
72

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines