Created
April 14, 2012 18:12
-
-
Save vovkasm/2386570 to your computer and use it in GitHub Desktop.
Simple dumb compare speed of Here::Template and Text::Xslate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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