ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/bench
(Generate patch)

Comparing Coro/eg/bench (file contents):
Revision 1.2 by root, Tue Jul 10 01:43:21 2001 UTC vs.
Revision 1.3 by root, Sat Jul 14 22:14:21 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}
19 17
20$b = new Coro sub { 18$b = new Coro sub {
21 # do a little unrolling... 19 # do a little unrolling...
22 while() { 20 while() {
23 $Coro::main->resume; $Coro::main->resume; $Coro::main->resume; 21 yield; yield; yield; yield; yield;
24 } 22 }
25}; 23};
26 24
27$b->resume; # the first resume is slow because it allocates all the memory 25yield;
28 26
29$main = $Coro::main; 27$main = $Coro::main;
30 28
31#*transfer = \&Coro::_transfer; 29*transfer = \&Coro::State::transfer;
32sub transfer { Coro::_transfer($_[0], $_[1]) }
33 30
34$c = Coro::_newprocess { 31$c = Coro::State::newprocess {
35 while() { 32 while() {
36 transfer($c, $main); transfer($c, $main); transfer($c, $main); 33 transfer($c, $main); transfer($c, $main);
34 transfer($c, $main); transfer($c, $main);
37 } 35 }
38}; 36};
39 37
40transfer($main, $c); 38transfer($main, $c);
41 39
42timethese 100000, { 40timethese 100000, {
43 method => '$a->a; $a->a; $a->a; $a->a', 41 method => '$a->a; $a->a; $a->a; $a->a',
44 resume => '$b->resume; $b->resume', 42 resume => 'yield; yield',
45 transfer => 'transfer($main, $c); transfer($main, $c)', 43 transfer => 'transfer($main, $c); transfer($main, $c)',
46}; 44};

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines