--- cvsroot/Coro/eg/bench 2001/07/03 05:05:45 1.1 +++ cvsroot/Coro/eg/bench 2001/08/11 19:59:19 1.9 @@ -8,40 +8,63 @@ use Coro; use Benchmark; -$a = bless {}, main::; +sub a() { } -# do something similar, switch two global vars and return something +$a = bless {}, main::; -sub a { - $old = $current; - $current = $_[0]; +sub b { + my ($self) = shift; + $self->{b} = shift if @_; + $self->{b}; } -$b = new Coro sub { +$b = async { # do a little unrolling... while() { - $Coro::main->resume; $Coro::main->resume; $Coro::main->resume; + cede; cede; cede; cede; cede; } }; -$b->resume; # the first resume is slow because it allocates all the memory +cede; $main = $Coro::main; -sub transfer { - Coro::_transfer($_[0], $_[1]); +*transfer = \&Coro::State::transfer; + +sub doit0 { + while() { + # some unrolling here as well.. + transfer($c0, $main, 0); transfer($c0, $main, 0); + transfer($c0, $main, 0); transfer($c0, $main, 0); + transfer($c0, $main, 0); transfer($c0, $main, 0); + } } -$c = Coro::_newprocess { +sub doit1 { while() { - transfer($c, $main); transfer($c, $main); transfer($c, $main); + # some unrolling here as well.. + transfer($c1, $main, -1); transfer($c1, $main, -1); + transfer($c1, $main, -1); transfer($c1, $main, -1); + transfer($c1, $main, -1); transfer($c1, $main, -1); } -}; +} -transfer($main, $c); +$c0 = Coro::State::_newprocess [sub { + doit0(1,2,3,4,5,6,7,8,9); +}]; + +$c1 = Coro::State::_newprocess [sub { + doit1(1,2,3,4,5,6,7,8,9); +}]; + +transfer($main, $c0, 0); +transfer($main, $c1, -1); timethese 100000, { - method => '$a->a; $a->a; $a->a; $a->a', - resume => '$b->resume; $b->resume', - transfer => 'transfer($main, $c); transfer($main, $c)', + empty => '&a; &a', + method => '$a->b(5); $a->b(6)', + cede => 'cede', + transfer0=> 'transfer($main, $c0, 0)', + transfer1=> 'transfer($main, $c1, -1)', }; +