--- Coro/eg/bench 2001/07/10 01:43:21 1.2 +++ Coro/eg/bench 2001/07/21 18:21:45 1.6 @@ -10,37 +10,48 @@ $a = bless {}, main::; -# do something similar, switch two global vars and return something sub a { - $old = $current; - $current = $_[0]; } -$b = new Coro sub { +sub b { + my ($self) = shift; + my $num = shift; + return $num+1; +} + +$b = async { # do a little unrolling... while() { - $Coro::main->resume; $Coro::main->resume; $Coro::main->resume; + yield; yield; yield; yield; yield; } }; -$b->resume; # the first resume is slow because it allocates all the memory +yield; $main = $Coro::main; -#*transfer = \&Coro::_transfer; -sub transfer { Coro::_transfer($_[0], $_[1]) } +*transfer = \&Coro::State::transfer; -$c = Coro::_newprocess { +sub doit { while() { - transfer($c, $main); transfer($c, $main); transfer($c, $main); + # some unrolling here as well.. + transfer($c, $main); transfer($c, $main); + transfer($c, $main); transfer($c, $main); + transfer($c, $main); transfer($c, $main); } -}; +} + +$c = Coro::State::_newprocess [sub { + doit(1,2,3,4,5,6,7,8,9); +}]; transfer($main, $c); 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)', + yield => 'yield', + transfer => 'transfer($main, $c)', }; +