On Fri, Feb 08, 2002 at 10:35:11PM +1100, Bradley Baetz wrote:
> I was trying to work out why some output using templates was taking much
> more time than just using html directly. It turns out that a simple
> template which uses PROCESS is about twice as slow as just putting the
> block in directly. 

Yep, that makes sense.

> I'd expect process to have some overhead, but half the speed is a lot. The 
> ratio is also roughly the same as I change the number of bugs:

Making a subroutine call, either in Perl or in TT is going to add overhead 
that doesn't exist when you inline the code.  Here's a similar benchmark for
Perl:

  #!/usr/bin/perl -w

  use strict;
  use Benchmark;

  timethese(2**20, {
      inline  => sub { my $result = 10 + 20 + 30 },
      subcall => sub { my $result = add(10, 20, 30) },
  });

  sub add {
      my ($a, $b, $c) = @_;
      return $a + $b + $c;
  }

Benchmark: timing 1048576 iterations of inline, subcall...
    inline:  0 wallclock secs ( 0.25 usr + -0.01 sys =  0.24 CPU)
   subcall:  5 wallclock secs ( 4.17 usr +  0.00 sys =  4.17 CPU)

Here we see that making a sub call is roughly 16 times slower than 
inlining the code.  But really, we're just benchmarking something against
nothing and the end result doesn't make a lot of sense.

That's not to say that benchmarking isn't extremely useful in helping to 
determine a) which parts of your code are slower than others and b) if
successive versions are getting faster or slower (see other thread).  But
unfortunately, benchmarking can be a minefield and knowing what to measure
and how to measure it accurately is often far from obvious.

Hope that helps
A

(thinking that we really need a formal benchmarking suite....any offers?)



Reply via email to