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.2 by root, Tue Jul 10 01:43:21 2001 UTC vs.
Revision 1.21 by root, Mon May 30 02:21:54 2011 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;
25 cede; cede; cede; cede; cede;
24 } 26 }
25}; 27};
26 28
27$b->resume; # the first resume is slow because it allocates all the memory 29cede;
28 30
29$main = $Coro::main; 31$main = $Coro::main;
30 32
31#*transfer = \&Coro::_transfer; 33*transfer = \&Coro::State::transfer;
32sub transfer { Coro::_transfer($_[0], $_[1]) }
33 34
34$c = Coro::_newprocess { 35sub doit0 {
35 while() { 36 while() {
37 # some unrolling here as well..
36 transfer($c, $main); 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);
41 transfer($c0, $main); transfer($c0, $main);
37 } 42 }
43}
44
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}
54
55$c0 = new Coro::State sub {
56 doit0(1,2,3,4,5,6,7,8,9);
38}; 57};
39 58
40transfer($main, $c); 59$c1 = new Coro::State sub {
60 doit1(1,2,3,4,5,6,7,8,9);
61};
41 62
63#$c0->save (0);
64#$c1->save (-1);
65
66transfer($main, $c0);
67transfer($main, $c1);
68
69#Coro::State::enable_times 1;
70#use Coro::Debug; Coro::Debug::command "ps";#d#
71#(async {
42timethese 100000, { 72timethese 5000000, {
43 method => '$a->a; $a->a; $a->a; $a->a', 73 function => 'a(5); a(6)',
44 resume => '$b->resume; $b->resume', 74 method => '$a->b(5); $a->b(6)',
75 cede => 'cede',
45 transfer => 'transfer($main, $c); transfer($main, $c)', 76 transfer0 => 'transfer($main, $c0)',
77 transfer1 => 'transfer($main, $c1)',
46}; 78};
79#})->join;
80#use Coro::Debug; Coro::Debug::command "ps";#d#
81
82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines