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.4 by root, Tue Jul 17 00:24:15 2001 UTC vs.
Revision 1.15 by root, Mon Dec 4 13:47:56 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
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$|=1;
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
32$c = Coro::State::_newprocess [sub { 34sub doit0 {
33 while() { 35 while() {
36 # some unrolling here as well..
34 transfer($c, $main); transfer($c, $main); 37 transfer($c0, $main); transfer($c0, $main);
35 transfer($c, $main); transfer($c, $main); 38 transfer($c0, $main); transfer($c0, $main);
39 transfer($c0, $main); transfer($c0, $main);
40 transfer($c0, $main); transfer($c0, $main);
36 } 41 }
37}]; 42}
38 43
39transfer($main, $c); 44sub doit1 {
45 while() {
46 # some unrolling here as well..
47 transfer($c1, $main); transfer($c1, $main);
48 transfer($c1, $main); transfer($c1, $main);
49 transfer($c1, $main); transfer($c1, $main);
50 transfer($c1, $main); transfer($c1, $main);
51 }
52}
40 53
41timethese 100000, { 54$c0 = new Coro::State sub {
42 method => '$a->a; $a->a; $a->a; $a->a', 55 doit0(1,2,3,4,5,6,7,8,9);
43 resume => 'yield; yield',
44 transfer => 'transfer($main, $c); transfer($main, $c)',
45}; 56};
57
58$c1 = new Coro::State sub {
59 doit1(1,2,3,4,5,6,7,8,9);
60};
61
62$c0->save (0);
63$c1->save (-1);
64
65transfer($main, $c0);
66transfer($main, $c1);
67
68timethese 1000000, {
69 function => 'a(5); a(6)',
70 method => '$a->b(5); $a->b(6)',
71 cede => 'cede',
72 transfer0 => 'transfer($main, $c0)',
73 transfer1 => 'transfer($main, $c1)',
74};
75
76
77

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines