--- cvsroot/Coro/eg/bench 2001/07/03 05:05:45 1.1 +++ cvsroot/Coro/eg/bench 2006/11/24 15:34:33 1.12 @@ -8,40 +8,65 @@ 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); + 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($c1, $main, -1); transfer($c1, $main, -1); } +} + +$c0 = new Coro::State sub { + doit0(1,2,3,4,5,6,7,8,9); }; -transfer($main, $c); +$c1 = new Coro::State sub { + doit1(1,2,3,4,5,6,7,8,9); +}; -timethese 100000, { - method => '$a->a; $a->a; $a->a; $a->a', - resume => '$b->resume; $b->resume', - transfer => 'transfer($main, $c); transfer($main, $c)', +transfer($main, $c0, 0); +transfer($main, $c1, -1); + +timethese 1000000, { + function => 'a(5); a(6)', + method => '$a->b(5); $a->b(6)', + cede => 'cede', + transfer0 => 'transfer($main, $c0, 0)', + transfer1 => 'transfer($main, $c1, -1)', }; +