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 |