ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Coro/eg/bench
Revision: 1.10
Committed: Sat Aug 25 21:32:05 2001 UTC (22 years, 9 months ago) by root
Branch: MAIN
CVS Tags: rel-2_5, rel-2_0, rel-2_1, rel-1_1, rel-1_0, rel-1_9, rel-1_2, rel-1_5, rel-1_4, rel-1_7, rel-1_6, rel-1_31
Changes since 1.9: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.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 root 1.8 sub a() { }
12    
13 root 1.1 $a = bless {}, main::;
14    
15 root 1.6 sub b {
16     my ($self) = shift;
17 root 1.7 $self->{b} = shift if @_;
18     $self->{b};
19 root 1.1 }
20    
21 root 1.4 $b = async {
22 root 1.1 # do a little unrolling...
23     while() {
24 root 1.8 cede; cede; cede; cede; cede;
25 root 1.1 }
26     };
27    
28 root 1.8 cede;
29 root 1.1
30     $main = $Coro::main;
31    
32 root 1.3 *transfer = \&Coro::State::transfer;
33 root 1.1
34 root 1.8 sub doit0 {
35     while() {
36     # some unrolling here as well..
37 root 1.9 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 root 1.8 }
41     }
42    
43     sub doit1 {
44 root 1.1 while() {
45 root 1.5 # some unrolling here as well..
46 root 1.9 transfer($c1, $main, -1); transfer($c1, $main, -1);
47     transfer($c1, $main, -1); transfer($c1, $main, -1);
48     transfer($c1, $main, -1); transfer($c1, $main, -1);
49 root 1.1 }
50 root 1.6 }
51    
52 root 1.8 $c0 = Coro::State::_newprocess [sub {
53     doit0(1,2,3,4,5,6,7,8,9);
54     }];
55    
56     $c1 = Coro::State::_newprocess [sub {
57     doit1(1,2,3,4,5,6,7,8,9);
58 root 1.4 }];
59 root 1.1
60 root 1.9 transfer($main, $c0, 0);
61     transfer($main, $c1, -1);
62 root 1.1
63 root 1.10 timethese 1000000, {
64 root 1.6 empty => '&a; &a',
65     method => '$a->b(5); $a->b(6)',
66 root 1.8 cede => 'cede',
67     transfer0=> 'transfer($main, $c0, 0)',
68 root 1.9 transfer1=> 'transfer($main, $c1, -1)',
69 root 1.1 };
70 root 1.5