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