in reply to TT memory caching

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.

Replies are listed 'Best First'.
Re^2: TT memory caching
by december (Pilgrim) on Nov 08, 2009 at 20:33 UTC

    Thanks!

    You mention I'm unfairly benchmarking Template->new... But this is what I'm doing for all modules. So I guess TT uses a different (more scope-oriented) way of caching than the other two modules?

    Not that it would matter much in web applications, where frameworks like CGI::Application take care of caching on a higher, persistent level.

    I will add HTML::Template::Compiled to my benchmarks too. And perhaps Seamstress – if there's any point benchmarking that module speed-wise – but I'm having a tough time getting it packaged and installed properly on Debian.

    So thanks again for your insight, I'm just left wondering why TT seems to use a different sort of caching system than the other modules. I don't think I found any clues to this effect in the CPAN documentation at least...