… | |
… | |
6 | # call with two calls of transfer in a loop. |
6 | # call with two calls of transfer in a loop. |
7 | |
7 | |
8 | use Coro; |
8 | use Coro; |
9 | use Benchmark; |
9 | use Benchmark; |
10 | |
10 | |
|
|
11 | sub a($) { } |
|
|
12 | |
11 | $a = bless {}, main::; |
13 | $a = bless {}, main::; |
12 | |
|
|
13 | |
|
|
14 | sub a { |
|
|
15 | } |
|
|
16 | |
14 | |
17 | sub b { |
15 | sub b { |
18 | my ($self) = shift; |
16 | my ($self) = shift; |
19 | my $num = shift; |
17 | $self->{b} = shift if @_; |
20 | return $num+1; |
18 | $self->{b}; |
21 | } |
19 | } |
22 | |
20 | |
23 | $b = async { |
21 | $b = async { |
24 | # do a little unrolling... |
22 | # do a little unrolling... |
25 | while() { |
23 | while() { |
26 | yield; yield; yield; yield; yield; |
24 | cede; cede; cede; cede; cede; |
|
|
25 | cede; cede; cede; cede; cede; |
27 | } |
26 | } |
28 | }; |
27 | }; |
29 | |
28 | |
30 | yield; |
29 | cede; |
31 | |
30 | |
32 | $main = $Coro::main; |
31 | $main = $Coro::main; |
33 | |
32 | |
34 | *transfer = \&Coro::State::transfer; |
33 | *transfer = \&Coro::State::transfer; |
35 | |
34 | |
36 | sub doit { |
35 | sub doit0 { |
37 | while() { |
36 | while() { |
38 | # some unrolling here as well.. |
37 | # some unrolling here as well.. |
39 | transfer($c, $main); transfer($c, $main); |
38 | transfer($c0, $main); transfer($c0, $main); |
40 | transfer($c, $main); transfer($c, $main); |
39 | transfer($c0, $main); transfer($c0, $main); |
41 | transfer($c, $main); transfer($c, $main); |
40 | transfer($c0, $main); transfer($c0, $main); |
|
|
41 | transfer($c0, $main); transfer($c0, $main); |
42 | } |
42 | } |
43 | } |
43 | } |
44 | |
44 | |
45 | $c = Coro::State::_newprocess [sub { |
45 | sub doit1 { |
46 | doit(1,2,3,4,5,6,7,8,9); |
46 | while() { |
47 | }]; |
47 | # some unrolling here as well.. |
|
|
48 | transfer($c1, $main); transfer($c1, $main); |
|
|
49 | transfer($c1, $main); transfer($c1, $main); |
|
|
50 | transfer($c1, $main); transfer($c1, $main); |
|
|
51 | transfer($c1, $main); transfer($c1, $main); |
|
|
52 | } |
|
|
53 | } |
48 | |
54 | |
49 | transfer($main, $c); |
55 | $c0 = new Coro::State sub { |
50 | |
56 | doit0(1,2,3,4,5,6,7,8,9); |
51 | timethese 100000, { |
|
|
52 | empty => '&a; &a', |
|
|
53 | method => '$a->b(5); $a->b(6)', |
|
|
54 | yield => 'yield', |
|
|
55 | transfer => 'transfer($main, $c)', |
|
|
56 | }; |
57 | }; |
57 | |
58 | |
|
|
59 | $c1 = new Coro::State sub { |
|
|
60 | doit1(1,2,3,4,5,6,7,8,9); |
|
|
61 | }; |
|
|
62 | |
|
|
63 | #$c0->save (0); |
|
|
64 | #$c1->save (-1); |
|
|
65 | |
|
|
66 | transfer($main, $c0); |
|
|
67 | transfer($main, $c1); |
|
|
68 | |
|
|
69 | #Coro::State::enable_times 1; |
|
|
70 | #use Coro::Debug; Coro::Debug::command "ps";#d# |
|
|
71 | #(async { |
|
|
72 | timethese 5000000, { |
|
|
73 | function => 'a(5); a(6)', |
|
|
74 | method => '$a->b(5); $a->b(6)', |
|
|
75 | cede => 'cede', |
|
|
76 | transfer0 => 'transfer($main, $c0)', |
|
|
77 | transfer1 => 'transfer($main, $c1)', |
|
|
78 | }; |
|
|
79 | #})->join; |
|
|
80 | #use Coro::Debug; Coro::Debug::command "ps";#d# |
|
|
81 | |
|
|
82 | |
|
|
83 | |