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.


In reply to Re: TT memory caching by WizardOfUz
in thread TT memory caching by december

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.