ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/bench
Revision: 1.19
Committed: Sat Nov 8 04:31:28 2008 UTC (15 years, 6 months ago) by root
Branch: MAIN
CVS Tags: rel-4_91, rel-5_1, rel-5_0, rel-4_9, rel-6_13, rel-4_901, rel-5_11, rel-5_12, rel-5_14, rel-5_132, rel-5_131, rel-4_911, rel-4_912
Changes since 1.18: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/usr/bin/perl
2
3 # ->resume is not exactly cheap (it saves/restores a LOT
4 # of global variables), but shouldn't be slow. just to show
5 # how fast it is, this little proggie compares a normal subroutine
6 # call with two calls of transfer in a loop.
7
8 use Coro;
9 use Benchmark;
10
11 sub a($) { }
12
13 $a = bless {}, main::;
14
15 sub b {
16 my ($self) = shift;
17 $self->{b} = shift if @_;
18 $self->{b};
19 }
20
21 $b = async {
22 # do a little unrolling...
23 while() {
24 cede; cede; cede; cede; cede;
25 cede; cede; cede; cede; cede;
26 }
27 };
28
29 cede;
30
31 $main = $Coro::main;
32
33 *transfer = \&Coro::State::transfer;
34
35 sub doit0 {
36 while() {
37 # some unrolling here as well..
38 transfer($c0, $main); transfer($c0, $main);
39 transfer($c0, $main); transfer($c0, $main);
40 transfer($c0, $main); transfer($c0, $main);
41 transfer($c0, $main); transfer($c0, $main);
42 }
43 }
44
45 sub doit1 {
46 while() {
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 }
54
55 $c0 = new Coro::State sub {
56 doit0(1,2,3,4,5,6,7,8,9);
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 #(async {
70 timethese 5000000, {
71 function => 'a(5); a(6)',
72 method => '$a->b(5); $a->b(6)',
73 cede => 'cede',
74 transfer0 => 'transfer($main, $c0)',
75 transfer1 => 'transfer($main, $c1)',
76 };
77 #})->join;
78
79
80