You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Barrie Slaymaker <ba...@slaysys.com> on 2000/06/08 18:09:08 UTC

Method overhead benchmarks [Was: [performance/benchmark] printing techniques]

Stephen Zander wrote:
> 
> As Matt has already commented, in the handler the method call
> overheads swamps all the other activities.

Just to clarify: that's only important if you are doing very few other
activities, or if those other activities also include a high percentage 
of method calls:

###### Using an empty A::a() (see below):

Benchmark: running $a->a(), A->a(), A::a( "A" ), A::a( $a ), A::a(), a(), each for at least 3 CPU seconds...
   $a->a():  4 wallclock secs ( 3.24 usr +  0.02 sys =  3.26 CPU) @ 511465.64/s (n=1667378)
    A->a():  2 wallclock secs ( 3.28 usr +  0.00 sys =  3.28 CPU) @ 290696.34/s (n=953484)
A::a( "A" ):  3 wallclock secs ( 3.08 usr +  0.00 sys =  3.08 CPU) @ 610704.55/s (n=1880970)
A::a( $a ):  3 wallclock secs ( 3.07 usr +  0.00 sys =  3.07 CPU) @ 623101.63/s (n=1912922)
    A::a():  3 wallclock secs ( 3.22 usr +  0.00 sys =  3.22 CPU) @ 611970.19/s (n=1970544)
       a():  3 wallclock secs ( 3.14 usr +  0.00 sys =  3.14 CPU) @ 622945.22/s (n=1956048)

                Rate   A->a()  $a->a() A::a( "A" )   A::a()       a() A::a( $a )
A->a()      290696/s       --     -43%        -52%     -52%      -53%       -53%
$a->a()     511466/s      76%       --        -16%     -16%      -18%       -18%
A::a( "A" ) 610705/s     110%      19%          --      -0%       -2%        -2%
A::a()      611970/s     111%      20%          0%       --       -2%        -2%
a()         622945/s     114%      22%          2%       2%        --        -0%
A::a( $a )  623102/s     114%      22%          2%       2%        0%         --

###### And doing some trivial work in A::a():

[barries@jester tmp]$ perl ./cmp2
Name "A::b" used only once: possible typo at ./cmp2 line 7.
Benchmark: running $a->a(), A->a(), A::a( "A" ), A::a( $a ), a(), each for at least 3 CPU seconds...
   $a->a():  5 wallclock secs ( 3.19 usr +  0.00 sys =  3.19 CPU) @ 64346.39/s (n=205265)
    A->a():  4 wallclock secs ( 3.21 usr +  0.00 sys =  3.21 CPU) @ 54105.30/s (n=173678)
A::a( "A" ):  2 wallclock secs ( 3.09 usr +  0.00 sys =  3.09 CPU) @ 70333.66/s (n=217331)
A::a( $a ):  3 wallclock secs ( 3.19 usr +  0.00 sys =  3.19 CPU) @ 68128.84/s (n=217331)
       a():  4 wallclock secs ( 3.10 usr +  0.00 sys =  3.10 CPU) @ 72231.29/s (n=223917)

               Rate      A->a()     $a->a()  A::a( $a ) A::a( "A" )         a()
A->a()      54105/s          --        -16%        -21%        -23%        -25%
$a->a()     64346/s         19%          --         -6%         -9%        -11%
A::a( $a )  68129/s         26%          6%          --         -3%         -6%
A::a( "A" ) 70334/s         30%          9%          3%          --         -3%
a()         72231/s         34%         12%          6%          3%          --



You can see that even doing a few things in A::a() cause the relative slowdown
due to method call overhead to drop significantly.  I suspect that your opcode
count has more to do with it than method overhead, unless I've goofed the
benchmarks somehow.

Hmmm, maybe this shows it best (though I did tweak aggrlist_print to
print STDERR):


[barries@jester tmp]$ perl ./aggr_cmp  2> /dev/null
Benchmark: running $a->aggrlist_print(), A->aggrlist_print(), aggrlist_print( $a ), each for at least 3 CPU seconds...
$a->aggrlist_print():  3 wallclock secs ( 2.69 usr +  0.41 sys =  3.10 CPU) @ 15104.19/s (n=46823)
A->aggrlist_print():  3 wallclock secs ( 2.72 usr +  0.41 sys =  3.13 CPU) @ 14492.01/s (n=45360)
aggrlist_print( $a ):  3 wallclock secs ( 2.81 usr +  0.24 sys =  3.05 CPU) @ 15529.18/s (n=47364)

                        Rate A->aggrlist_print() $a->aggrlist_print() aggrlist_print( $a )
A->aggrlist_print()  14492/s                  --                  -4%                  -7%
$a->aggrlist_print() 15104/s                  4%                   --                  -3%
aggrlist_print( $a ) 15529/s                  7%                   3%                   --


- Barrie

[barries@jester tmp]$ cat cmp
#!/usr/local/bin/perl -w

## cmp

package A ;

use Benchmark qw( cmpthese ) ;

sub a {}

my $a = bless {}, 'A' ;

cmpthese( -3, {
   'a()'         => sub { a() },
   'A::a()'      => sub { A::a() },
   'A::a( "A" )' => sub { A::a( "A" ) },
   'A::a( $a )'  => sub { A::a( $a )  },
   'A->a()'      => sub { A->a()      },
   '$a->a()'     => sub { $a->a()     },
} ) ;


[barries@jester tmp]$ cat cmp2
#!/usr/local/bin/perl -w

## cmp2

package A ;

$b = {} ;

sub a {
   my $self = shift ;
   my ( $a, $b, $c ) = @_ ;
   $b->{FOO} = 'bar' ;
}

use Benchmark qw( cmpthese ) ;

my $a = bless {}, 'A' ;

cmpthese( -3, {
   'a()'         => sub { a()         },
   'A::a( "A" )' => sub { A::a( "A" ) },
   'A::a( $a )'  => sub { A::a( $a )  },
   'A->a()'      => sub { A->a()      },
   '$a->a()'     => sub { $a->a()     },
} ) ;


[barries@jester tmp]$ cat aggr_cmp 
#!/usr/local/bin/perl -w

package A ;

sub aggrlist_print{
   my @buffer = ();
   push @buffer,"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n";
   push @buffer,"<HTML>\n";
   push @buffer,"  <HEAD>\n";
   push @buffer,"    <TITLE>\n";
   push @buffer,"      Test page\n";
   push @buffer,"    </TITLE>\n";
   push @buffer,"  </HEAD>\n";
   push @buffer,"  <BODY BGCOLOR=\"black\" TEXT=\"white\">\n";
   push @buffer,"    <H1> \n";
   push @buffer,"      Test page \n";
   push @buffer,"    </H1>\n";
   push @buffer,"    <A HREF=\"foo.html\">foo</A>\n";
   push @buffer,"    <HR>\n";
   push @buffer,"  </BODY>\n";
   push @buffer,"</HTML>\n";
   print STDERR @buffer;



use Benchmark qw( cmpthese ) ;

my $a = bless {}, 'A' ;

cmpthese( -3, {
   'aggrlist_print( $a )' => sub { aggrlist_print( $a ) },
   'A->aggrlist_print()'  => sub { A->aggrlist_print()  },
   '$a->aggrlist_print()' => sub { $a->aggrlist_print() },
} ) ;

Re: Method overhead benchmarks [Was: [performance/benchmark] printingtechniques]

Posted by Barrie Slaymaker <ba...@slaysys.com>.
Matt Sergeant wrote:
> 
> You also forgot that print() goes to a tied STDOUT, which is even more of
> an overhead...

Yeah, that'd probably swamp almost all other effects Stas is testing right
there, and it explains Stas's test results when varying $|.

- Barrie

Re: Method overhead benchmarks [Was: [performance/benchmark] printing techniques]

Posted by Matt Sergeant <ma...@sergeant.org>.
On Thu, 8 Jun 2000, Barrie Slaymaker wrote:

> Stephen Zander wrote:
> > 
> > As Matt has already commented, in the handler the method call
> > overheads swamps all the other activities.
> 
> Just to clarify: that's only important if you are doing very few other
> activities, or if those other activities also include a high percentage 
> of method calls:

You also forgot that print() goes to a tied STDOUT, which is even more of
an overhead...

-- 
<Matt/>

Fastnet Software Ltd. High Performance Web Specialists
Providing mod_perl, XML, Sybase and Oracle solutions
Email for training and consultancy availability.
http://sergeant.org http://xml.sergeant.org