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.10 by root, Sat Aug 25 21:32:05 2001 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;
22 } 25 }
23}; 26};
24 27
25yield; 28cede;
26 29
27$main = $Coro::main; 30$main = $Coro::main;
28 31
29*transfer = \&Coro::State::transfer; 32*transfer = \&Coro::State::transfer;
30 33
31$c = Coro::State::_newprocess [sub { 34sub doit0 {
32 while() { 35 while() {
33 # some unrolling here as well.. 36 # some unrolling here as well..
34 transfer($c, $main); transfer($c, $main); 37 transfer($c0, $main, 0); transfer($c0, $main, 0);
35 transfer($c, $main); transfer($c, $main); 38 transfer($c0, $main, 0); transfer($c0, $main, 0);
36 transfer($c, $main); transfer($c, $main); 39 transfer($c0, $main, 0); transfer($c0, $main, 0);
37 } 40 }
41}
42
43sub doit1 {
44 while() {
45 # some unrolling here as well..
46 transfer($c1, $main, -1); transfer($c1, $main, -1);
47 transfer($c1, $main, -1); transfer($c1, $main, -1);
48 transfer($c1, $main, -1); transfer($c1, $main, -1);
49 }
50}
51
52$c0 = Coro::State::_newprocess [sub {
53 doit0(1,2,3,4,5,6,7,8,9);
38}]; 54}];
39 55
40transfer($main, $c); 56$c1 = Coro::State::_newprocess [sub {
57 doit1(1,2,3,4,5,6,7,8,9);
58}];
41 59
60transfer($main, $c0, 0);
61transfer($main, $c1, -1);
62
42timethese 100000, { 63timethese 1000000, {
64 empty => '&a; &a',
43 method => '$a->a; $a->a', 65 method => '$a->b(5); $a->b(6)',
44 resume => 'yield', 66 cede => 'cede',
45 transfer => 'transfer($main, $c)', 67 transfer0=> 'transfer($main, $c0, 0)',
68 transfer1=> 'transfer($main, $c1, -1)',
46}; 69};
47 70

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines