--- Coro/eg/bench 2001/07/14 22:14:21 1.3 +++ Coro/eg/bench 2001/08/11 19:59:19 1.9 @@ -8,37 +8,63 @@ use Coro; use Benchmark; -$a = bless {}, main::; +sub a() { } +$a = bless {}, main::; -sub a { - $n++; # do something to taint the benchmark results ;) +sub b { + my ($self) = shift; + $self->{b} = shift if @_; + $self->{b}; } -$b = new Coro sub { +$b = async { # do a little unrolling... while() { - yield; yield; yield; yield; yield; + cede; cede; cede; cede; cede; } }; -yield; +cede; $main = $Coro::main; *transfer = \&Coro::State::transfer; -$c = Coro::State::newprocess { +sub doit0 { while() { - transfer($c, $main); transfer($c, $main); - transfer($c, $main); transfer($c, $main); + # 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); } -}; +} + +sub doit1 { + while() { + # 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 => 'yield; yield', - 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)', }; +