… | |
… | |
8 | use Coro; |
8 | use Coro; |
9 | use Benchmark; |
9 | use Benchmark; |
10 | |
10 | |
11 | $a = bless {}, main::; |
11 | $a = bless {}, main::; |
12 | |
12 | |
13 | |
|
|
14 | sub a { |
13 | sub b { |
15 | $n++; # do something to taint the benchmark results ;) |
14 | my ($self) = shift; |
|
|
15 | $self->{b} = shift if @_; |
|
|
16 | $self->{b}; |
16 | } |
17 | } |
17 | $|=1; |
|
|
18 | |
18 | |
19 | $b = async { |
19 | $b = async { |
20 | # do a little unrolling... |
20 | # do a little unrolling... |
21 | while() { |
21 | while() { |
22 | yield; yield; yield; yield; yield; |
22 | yield; yield; yield; yield; yield; |
… | |
… | |
27 | |
27 | |
28 | $main = $Coro::main; |
28 | $main = $Coro::main; |
29 | |
29 | |
30 | *transfer = \&Coro::State::transfer; |
30 | *transfer = \&Coro::State::transfer; |
31 | |
31 | |
32 | $c = Coro::State::_newprocess [sub { |
32 | sub doit { |
33 | while() { |
33 | while() { |
|
|
34 | # some unrolling here as well.. |
|
|
35 | transfer($c, $main); transfer($c, $main); |
34 | transfer($c, $main); transfer($c, $main); |
36 | transfer($c, $main); transfer($c, $main); |
35 | transfer($c, $main); transfer($c, $main); |
37 | transfer($c, $main); transfer($c, $main); |
36 | } |
38 | } |
|
|
39 | } |
|
|
40 | |
|
|
41 | $c = Coro::State::_newprocess [sub { |
|
|
42 | doit(1,2,3,4,5,6,7,8,9); |
37 | }]; |
43 | }]; |
38 | |
44 | |
39 | transfer($main, $c); |
45 | transfer($main, $c); |
40 | |
46 | |
41 | timethese 100000, { |
47 | timethese 100000, { |
42 | method => '$a->a; $a->a; $a->a; $a->a', |
48 | empty => '&a; &a', |
43 | resume => 'yield; yield', |
49 | method => '$a->b(5); $a->b(6)', |
|
|
50 | yield => 'yield', |
44 | transfer => 'transfer($main, $c); transfer($main, $c)', |
51 | transfer => 'transfer($main, $c)', |
45 | }; |
52 | }; |
|
|
53 | |