Skip to content

Instantly share code, notes, and snippets.

@vovkasm
Created April 14, 2012 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vovkasm/2386570 to your computer and use it in GitHub Desktop.
Save vovkasm/2386570 to your computer and use it in GitHub Desktop.
Simple dumb compare speed of Here::Template and Text::Xslate
#!perl
use 5.014;
use warnings;
use lib::abs './Here-Template/lib';
use Here::Template;
use Text::Xslate;
use Benchmark qw(cmpthese);
my %vpath = ( 'test.tx' => <<'XSLATETT' );
Hello, my pid is <: $a :>
Let's show array: <:
for $b -> $i {
$i; " "
}
:>
And long string: <: $c :>
XSLATETT
my $tx = Text::Xslate->new(path=>\%vpath,type=>'text');
my $vars = { a => $$, b => [1..100], c => ("test" x 50) };
say for_here_template($vars);
say for_xslate($tx, $vars);
cmpthese(-5, {
'here-template' => sub { for_here_template($vars) },
'xslate' => sub { for_xslate($tx, $vars) },
});
sub for_here_template {
my $vars = shift;
return <<'TMPL';
Hello, my pid is <?= $vars->{a} ?>
Let's show array: <?
foreach (@{$vars->{b}}) {
$here .= "$_ ";
}
?>
And long string: <?= $vars->{c} ?>
TMPL
}
sub for_xslate {
my ($tx, $vars) = @_;
return $tx->render('test.tx', $vars);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment