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.5 by root, Tue Jul 17 15:42:28 2001 UTC vs.
Revision 1.18 by root, Sun Jan 20 10:22:07 2008 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
14sub a { 15sub b {
15 $n++; # do something to taint the benchmark results ;) 16 my ($self) = shift;
17 $self->{b} = shift if @_;
18 $self->{b};
16} 19}
17 20
18$b = async { 21$b = async {
19 # do a little unrolling... 22 # do a little unrolling...
20 while() { 23 while() {
21 yield; yield; yield; yield; yield; 24 cede; cede; cede; cede; cede;
25 cede; cede; cede; cede; cede;
22 } 26 }
23}; 27};
24 28
25yield; 29cede;
26 30
27$main = $Coro::main; 31$main = $Coro::main;
28 32
29*transfer = \&Coro::State::transfer; 33*transfer = \&Coro::State::transfer;
30 34
31$c = Coro::State::_newprocess [sub { 35sub doit0 {
32 while() { 36 while() {
33 # some unrolling here as well.. 37 # some unrolling here as well..
34 transfer($c, $main); transfer($c, $main); 38 transfer($c0, $main); transfer($c0, $main);
35 transfer($c, $main); transfer($c, $main); 39 transfer($c0, $main); transfer($c0, $main);
36 transfer($c, $main); transfer($c, $main); 40 transfer($c0, $main); transfer($c0, $main);
41 transfer($c0, $main); transfer($c0, $main);
37 } 42 }
38}]; 43}
39 44
40transfer($main, $c); 45sub doit1 {
46 while() {
47 # some unrolling here as well..
48 transfer($c1, $main); transfer($c1, $main);
49 transfer($c1, $main); transfer($c1, $main);
50 transfer($c1, $main); transfer($c1, $main);
51 transfer($c1, $main); transfer($c1, $main);
52 }
53}
41 54
42timethese 100000, { 55$c0 = new Coro::State sub {
43 method => '$a->a; $a->a', 56 doit0(1,2,3,4,5,6,7,8,9);
44 resume => 'yield',
45 transfer => 'transfer($main, $c)',
46}; 57};
47 58
59$c1 = new Coro::State sub {
60 doit1(1,2,3,4,5,6,7,8,9);
61};
62
63#$c0->save (0);
64#$c1->save (-1);
65
66transfer($main, $c0);
67transfer($main, $c1);
68
69timethese 5000000, {
70 function => 'a(5); a(6)',
71 method => '$a->b(5); $a->b(6)',
72 cede => 'cede',
73 transfer0 => 'transfer($main, $c0)',
74 transfer1 => 'transfer($main, $c1)',
75};
76
77
78

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines