Try this:
use strict;
use warnings;
use Template;
use Benchmark qw( :hireswallclock );
my $tt_2 = Template->new( INCLUDE_PATH => '/home/joerg' );
# precache
doit_1();
doit_2();
Benchmark::cmpthese(
10000,
{
'doit_1' => \&doit_1,
'doit_2' => \&doit_2
}
);
sub doit_1 {
my $tt_1 = Template->new( INCLUDE_PATH => '/home/joerg' );
my $vars = { HELLO_WORLD => 'Hello, World!' };
$tt_1->process( 'test.tt', $vars, \( my $void ) );
return;
}
sub doit_2 {
my $vars = { HELLO_WORLD => 'Hello, World!' };
$tt_2->process( 'test.tt', $vars, \( my $void ) );
return;
}
# joerg@Marvin:~> '/home/joerg/benchmark.pl'
# Rate doit_1 doit_2
# doit_1 627/s -- -90%
# doit_2 6329/s 909% --
At the moment, you are benchmarking Template->new, which isn't really fair.
Update: You might also want to include HTML::Template::Compiled in your benchmarks. It's fast. Really fast.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|