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.7 by root, Sat Jul 21 19:53:29 2001 UTC vs.
Revision 1.21 by root, Mon May 30 02:21:54 2011 UTC

5# how fast it is, this little proggie compares a normal subroutine 5# how fast it is, this little proggie compares a normal subroutine
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
11sub a($) { }
10 12
11$a = bless {}, main::; 13$a = bless {}, main::;
12 14
13sub b { 15sub b {
14 my ($self) = shift; 16 my ($self) = shift;
17} 19}
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;
25 cede; cede; cede; cede; cede;
23 } 26 }
24}; 27};
25 28
26yield; 29cede;
27 30
28$main = $Coro::main; 31$main = $Coro::main;
29 32
30*transfer = \&Coro::State::transfer; 33*transfer = \&Coro::State::transfer;
31 34
32sub doit { 35sub doit0 {
33 while() { 36 while() {
34 # some unrolling here as well.. 37 # some unrolling here as well..
35 transfer($c, $main); transfer($c, $main); 38 transfer($c0, $main); transfer($c0, $main);
36 transfer($c, $main); transfer($c, $main); 39 transfer($c0, $main); transfer($c0, $main);
37 transfer($c, $main); transfer($c, $main); 40 transfer($c0, $main); transfer($c0, $main);
41 transfer($c0, $main); transfer($c0, $main);
38 } 42 }
39} 43}
40 44
41$c = Coro::State::_newprocess [sub { 45sub doit1 {
42 doit(1,2,3,4,5,6,7,8,9); 46 while() {
43}]; 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}
44 54
45transfer($main, $c); 55$c0 = new Coro::State sub {
46 56 doit0(1,2,3,4,5,6,7,8,9);
47timethese 100000, {
48 empty => '&a; &a',
49 method => '$a->b(5); $a->b(6)',
50 yield => 'yield',
51 transfer => 'transfer($main, $c)',
52}; 57};
53 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
69#Coro::State::enable_times 1;
70#use Coro::Debug; Coro::Debug::command "ps";#d#
71#(async {
72timethese 5000000, {
73 function => 'a(5); a(6)',
74 method => '$a->b(5); $a->b(6)',
75 cede => 'cede',
76 transfer0 => 'transfer($main, $c0)',
77 transfer1 => 'transfer($main, $c1)',
78};
79#})->join;
80#use Coro::Debug; Coro::Debug::command "ps";#d#
81
82

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines