You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matt Sergeant <ma...@sergeant.org> on 2000/02/17 11:18:29 UTC
Re: choosing the right benchmark code
On Thu, 17 Feb 2000, Doug MacEachern wrote:
> On Wed, 16 Feb 2000, Stas Bekman wrote:
>
> > I've discovered a weird thing while working the perlformance section of
> > the guide. I wanted to show that methods are a little bit slower than
> > functions. I wrote the benchmark to prove this, but the results I've
> > received were reversed to my expectations -- the methods were faster than
> > the functions.
>
> for something like this, less code == better test, CGI.pm does lots of
> things under the covers.
>
> all you need is this:
>
> package Foo;
>
> sub bar { }
>
> use strict;
> use Benchmark;
>
> timethese(50_000, {
> method => sub {
> Foo->bar();
> },
> function => sub {
> Foo::bar('Foo');
> },
> });
>
> Benchmark: timing 50000 iterations of function, method...
> function: 1 wallclock secs ( 0.43 usr + 0.00 sys = 0.43 CPU)
> method: 2 wallclock secs ( 0.89 usr + 0.00 sys = 0.89 CPU)
It's also worth noting that this is _very_ much dependant on your perl
version. Later versions of perl do much better method caching - I believe
in the current devel version of perl method calls are only very slightly
slower - rather than 2 times slower.
--
<Matt/>
Details: FastNet Software Ltd - XML, Perl, Databases.
Tagline: High Performance Web Solutions
Web Sites: http://come.to/fastnet http://sergeant.org
Available for Consultancy, Contracts and Training.
yanf@nadym.ru
Posted by YANF WSCB <YA...@nadym.ru>.
unsubscribe
Re: choosing the right benchmark code
Posted by Doug MacEachern <do...@pobox.com>.
On Thu, 17 Feb 2000, Matt Sergeant wrote:
>
> It's also worth noting that this is _very_ much dependant on your perl
> version. Later versions of perl do much better method caching - I believe
> in the current devel version of perl method calls are only very slightly
> slower - rather than 2 times slower.
only a little better though, newer Perls make Foo->method() a bit faster
(some constant folding magic), but not Foo->$method(). and the
improvement does not address the @ISA lookup that still happens in either
case.
Re: choosing the right benchmark code
Posted by Autarch <au...@urth.org>.
On Thu, 17 Feb 2000, Matt Sergeant wrote:
> It's also worth noting that this is _very_ much dependant on your perl
> version. Later versions of perl do much better method caching - I believe
> in the current devel version of perl method calls are only very slightly
> slower - rather than 2 times slower.
At the risk of getting horrible completely off-topic:
9:46 ~ $ perl5.00503 -w t.pl
Benchmark: timing 1000000 iterations of function, method...
function: 3 wallclock secs ( 3.87 usr + 0.00 sys = 3.87 CPU)
method: 6 wallclock secs ( 5.70 usr + 0.00 sys = 5.70 CPU)
9:47 ~ $ perl5.00503 -w t.pl
Benchmark: timing 1000000 iterations of function, method...
function: 5 wallclock secs ( 3.85 usr + 0.00 sys = 3.85 CPU)
method: 6 wallclock secs ( 5.71 usr + 0.00 sys = 5.71 CPU)
9:47 ~ $ perl5.00503 -w t.pl
Benchmark: timing 1000000 iterations of function, method...
function: 3 wallclock secs ( 3.86 usr + 0.00 sys = 3.86 CPU)
method: 6 wallclock secs ( 5.70 usr + 0.00 sys = 5.70 CPU)
9:50 ~ $ /usr/local/perl5.5.65/bin/perl5.5.650 -w t.pl
Benchmark: timing 1000000 iterations of function, method...
function: 2 wallclock secs ( 1.67 usr + 0.01 sys = 1.68 CPU) @
595238.10/s (n=1000000)
method: 5 wallclock secs ( 5.62 usr + 0.00 sys = 5.62 CPU) @
177935.94/s (n=1000000)
9:51 ~ $ /usr/local/perl5.5.65/bin/perl5.5.650 -w t.pl
Benchmark: timing 1000000 iterations of function, method...
function: 0 wallclock secs ( 1.67 usr + 0.00 sys = 1.67 CPU) @
598802.40/s (n=1000000)
method: 5 wallclock secs ( 5.62 usr + 0.00 sys = 5.62 CPU) @
177935.94/s (n=1000000)
9:51 ~ $ /usr/local/perl5.5.65/bin/perl5.5.650 -w t.pl
Benchmark: timing 1000000 iterations of function, method...
function: 2 wallclock secs ( 1.68 usr + 0.00 sys = 1.68 CPU) @
595238.10/s (n=1000000)
method: 6 wallclock secs ( 5.61 usr + 0.00 sys = 5.61 CPU) @
178253.12/s (n=1000000)
Well, judging from this function calls have somehow been sped up by two
by a factor of 2 but methods are untouched. I wonder if this test is
somehow unrepresentative (I also wonder why I got 0 wallclock seconds for
a test that took 1.68 CPU).
-dave
/*==================
www.urth.org
We await the New Sun
==================*/