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.1 by root, Tue Jul 3 05:05:45 2001 UTC vs.
Revision 1.4 by root, Tue Jul 17 00:24:15 2001 UTC

8use Coro; 8use Coro;
9use Benchmark; 9use Benchmark;
10 10
11$a = bless {}, main::; 11$a = bless {}, main::;
12 12
13# do something similar, switch two global vars and return something
14 13
15sub a { 14sub a {
16 $old = $current; 15 $n++; # do something to taint the benchmark results ;)
17 $current = $_[0];
18} 16}
17$|=1;
19 18
20$b = new Coro sub { 19$b = async {
21 # do a little unrolling... 20 # do a little unrolling...
22 while() { 21 while() {
23 $Coro::main->resume; $Coro::main->resume; $Coro::main->resume; 22 yield; yield; yield; yield; yield;
24 } 23 }
25}; 24};
26 25
27$b->resume; # the first resume is slow because it allocates all the memory 26yield;
28 27
29$main = $Coro::main; 28$main = $Coro::main;
30 29
31sub transfer { 30*transfer = \&Coro::State::transfer;
32 Coro::_transfer($_[0], $_[1]);
33}
34 31
35$c = Coro::_newprocess { 32$c = Coro::State::_newprocess [sub {
36 while() { 33 while() {
37 transfer($c, $main); transfer($c, $main); transfer($c, $main); 34 transfer($c, $main); transfer($c, $main);
35 transfer($c, $main); transfer($c, $main);
38 } 36 }
39}; 37}];
40 38
41transfer($main, $c); 39transfer($main, $c);
42 40
43timethese 100000, { 41timethese 100000, {
44 method => '$a->a; $a->a; $a->a; $a->a', 42 method => '$a->a; $a->a; $a->a; $a->a',
45 resume => '$b->resume; $b->resume', 43 resume => 'yield; yield',
46 transfer => 'transfer($main, $c); transfer($main, $c)', 44 transfer => 'transfer($main, $c); transfer($main, $c)',
47}; 45};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines