Skip to content

Instantly share code, notes, and snippets.

@gfx
Created April 16, 2010 04:06
Show Gist options
  • Save gfx/367990 to your computer and use it in GitHub Desktop.
Save gfx/367990 to your computer and use it in GitHub Desktop.
$ perl -Mblib benchmark/interpolate.pl
Perl/5.10.1 i686-linux
Text::Xslate/0.001
Text::MicroTemplate/0.11
Rate s///g mt xslate
s///g 7456/s -- -0% -77%
mt 7456/s 0% -- -77%
xslate 32880/s 341% 341% --
#!perl -w
use 5.010_000;
use strict;
use Text::Xslate::Compiler;
use Text::MicroTemplate qw(build_mt);
use Benchmark qw(:all);
use Config; printf "Perl/%vd %s\n", $^V, $Config{archname};
foreach my $mod(qw(Text::Xslate Text::MicroTemplate)){
say $mod, '/', $mod->VERSION;
}
my $n = shift(@ARGV) || 100;
my $x = Text::Xslate::Compiler->new
->compile_str("Hello, <?= \$lang ?> world!\n" x $n);
my $mt = build_mt("Hello, <?= \$_[0]->{lang} ?> world!\n" x $n);
my $subst_tmpl = qq{Hello, %lang% world!\n} x $n;
my $vars = {
lang => 'Template',
};
$x->render($vars) eq $mt->($vars) or die $x->render($vars);
# suppose PSGI response body
cmpthese -1 => {
xslate => sub {
my $body = [$x->render($vars)];
return;
},
mt => sub {
my $body = [$mt->($vars)];
return;
},
's///g' => sub {
my $body = [$subst_tmpl];
$body->[0] =~ s/%(\w+)%/$vars->{$1}/g;
return;
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment