ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/bench
Revision: 1.12
Committed: Fri Nov 24 15:34:33 2006 UTC (17 years, 6 months ago) by root
Branch: MAIN
CVS Tags: stack_sharing
Changes since 1.11: +8 -6 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 }
26 };
27
28 cede;
29
30 $main = $Coro::main;
31
32 *transfer = \&Coro::State::transfer;
33
34 sub doit0 {
35 while() {
36 # some unrolling here as well..
37 transfer($c0, $main, 0); transfer($c0, $main, 0);
38 transfer($c0, $main, 0); transfer($c0, $main, 0);
39 transfer($c0, $main, 0); transfer($c0, $main, 0);
40 transfer($c0, $main, 0); transfer($c0, $main, 0);
41 }
42 }
43
44 sub doit1 {
45 while() {
46 # some unrolling here as well..
47 transfer($c1, $main, -1); transfer($c1, $main, -1);
48 transfer($c1, $main, -1); transfer($c1, $main, -1);
49 transfer($c1, $main, -1); transfer($c1, $main, -1);
50 transfer($c1, $main, -1); transfer($c1, $main, -1);
51 }
52 }
53
54 $c0 = new Coro::State sub {
55 doit0(1,2,3,4,5,6,7,8,9);
56 };
57
58 $c1 = new Coro::State sub {
59 doit1(1,2,3,4,5,6,7,8,9);
60 };
61
62 transfer($main, $c0, 0);
63 transfer($main, $c1, -1);
64
65 timethese 1000000, {
66 function => 'a(5); a(6)',
67 method => '$a->b(5); $a->b(6)',
68 cede => 'cede',
69 transfer0 => 'transfer($main, $c0, 0)',
70 transfer1 => 'transfer($main, $c1, -1)',
71 };
72