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.1 by root, Tue Jul 3 05:05:45 2001 UTC vs.
Revision 1.12 by root, Fri Nov 24 15:34:33 2006 UTC

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 10
11sub a($) { }
12
11$a = bless {}, main::; 13$a = bless {}, main::;
12 14
13# do something similar, switch two global vars and return something
14
15sub a { 15sub b {
16 $old = $current; 16 my ($self) = shift;
17 $current = $_[0]; 17 $self->{b} = shift if @_;
18 $self->{b};
18} 19}
19 20
20$b = new Coro sub { 21$b = async {
21 # do a little unrolling... 22 # do a little unrolling...
22 while() { 23 while() {
23 $Coro::main->resume; $Coro::main->resume; $Coro::main->resume; 24 cede; cede; cede; cede; cede;
24 } 25 }
25}; 26};
26 27
27$b->resume; # the first resume is slow because it allocates all the memory 28cede;
28 29
29$main = $Coro::main; 30$main = $Coro::main;
30 31
31sub transfer { 32*transfer = \&Coro::State::transfer;
32 Coro::_transfer($_[0], $_[1]); 33
34sub doit0 {
35 while() {
36 # some unrolling here as well..
37 transfer($c0, $main, 0); transfer($c0, $main, 0);
38 transfer($c0, $main, 0); transfer($c0, $main, 0);
39 transfer($c0, $main, 0); transfer($c0, $main, 0);
40 transfer($c0, $main, 0); transfer($c0, $main, 0);
41 }
33} 42}
34 43
35$c = Coro::_newprocess { 44sub doit1 {
36 while() { 45 while() {
46 # some unrolling here as well..
37 transfer($c, $main); transfer($c, $main); transfer($c, $main); 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);
38 } 51 }
52}
53
54$c0 = new Coro::State sub {
55 doit0(1,2,3,4,5,6,7,8,9);
39}; 56};
40 57
41transfer($main, $c); 58$c1 = new Coro::State sub {
59 doit1(1,2,3,4,5,6,7,8,9);
60};
42 61
62transfer($main, $c0, 0);
63transfer($main, $c1, -1);
64
43timethese 100000, { 65timethese 1000000, {
44 method => '$a->a; $a->a; $a->a; $a->a', 66 function => 'a(5); a(6)',
45 resume => '$b->resume; $b->resume', 67 method => '$a->b(5); $a->b(6)',
68 cede => 'cede',
46 transfer => 'transfer($main, $c); transfer($main, $c)', 69 transfer0 => 'transfer($main, $c0, 0)',
70 transfer1 => 'transfer($main, $c1, -1)',
47}; 71};
72

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines