From 5c4dbd607ea9e90e5634f456d60e51010316474a Mon Sep 17 00:00:00 2001 From: Naoki Tomita Date: Mon, 8 Feb 2010 22:56:09 +0900 Subject: [PATCH] added benchmark script Benchmark: timing 1000 iterations of Template-Toolkit, Template::Semantic, Text::MicroTemplate... Template-Toolkit: 4 wallclock secs ( 4.33 usr + 0.03 sys = 4.36 CPU) @ 229.36/s (n=1000) Template::Semantic: 4 wallclock secs ( 3.18 usr + 0.03 sys = 3.21 CPU) @ 311.53/s (n=1000) Text::MicroTemplate: 1 wallclock secs ( 1.18 usr + 0.04 sys = 1.22 CPU) @ 819.67/s (n=1000) Rate Template-Toolkit Template::Semantic Text::MicroTemplate Template-Toolkit 229/s -- -26% -72% Template::Semantic 312/s 36% -- -62% Text::MicroTemplate 820/s 257% 163% -- --- MANIFEST.SKIP | 1 + bench/bench.pl | 46 ++++++++++++++++++++++++++++++++++++++++++++++ bench/tm.html | 21 +++++++++++++++++++++ bench/ts.html | 18 ++++++++++++++++++ bench/tt.html | 20 ++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 bench/bench.pl create mode 100644 bench/tm.html create mode 100644 bench/ts.html create mode 100644 bench/tt.html diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP index 9e5d266..2a20017 100644 --- a/MANIFEST.SKIP +++ b/MANIFEST.SKIP @@ -14,3 +14,4 @@ ^\. ^t/9\d_.*\.t \.sw[po]$ +^bench/ diff --git a/bench/bench.pl b/bench/bench.pl new file mode 100644 index 0000000..24eb2ed --- /dev/null +++ b/bench/bench.pl @@ -0,0 +1,46 @@ +use strict; +use warnings; +use Benchmark; + +use Template; +use Template::Semantic; +use Text::MicroTemplate::File; + +Benchmark::cmpthese( Benchmark::timethese(1000, { + 'Template-Toolkit' => sub { + my $tt = Template->new; + $tt->process('bench/tt.html', { + 'title' => 'foo & bar', + 'list' => [ + { 'name' => 'aaa', 'count' => '001' }, + { 'name' => 'aaa', 'count' => '002' }, + { 'name' => 'aaa', 'count' => '003' }, + ], + }, \my $out); + }, + + 'Template::Semantic' => sub { + my $out = Template::Semantic->process('bench/ts.html', { + 'title, h1' => 'foo & bar', + 'table.list tr' => [ + { '.name' => 'aaa', '.count' => '001' }, + { '.name' => 'aaa', '.count' => '002' }, + { '.name' => 'aaa', '.count' => '003' }, + ], + }); + my $r = $out->as_string; + }, + + 'Text::MicroTemplate' => sub { + my $tm = Text::MicroTemplate::File->new; + my $out = $tm->render_file('bench/tm.html', { + 'title' => 'foo & bar', + 'list' => [ + { 'name' => 'aaa', 'count' => '001' }, + { 'name' => 'aaa', 'count' => '002' }, + { 'name' => 'aaa', 'count' => '003' }, + ], + }); + my $r = $out->as_string; + }, +})); diff --git a/bench/tm.html b/bench/tm.html new file mode 100644 index 0000000..6b79456 --- /dev/null +++ b/bench/tm.html @@ -0,0 +1,21 @@ +? my $vars = $_[0]; + + + +<?= $vars->{title} ?> + + + +

{title} ?>

+ + + +? for my $item (@{ $vars->{list} || [] }) { + + +? } + +
{name} ?>{count} ?>
+ + + diff --git a/bench/ts.html b/bench/ts.html new file mode 100644 index 0000000..57158d5 --- /dev/null +++ b/bench/ts.html @@ -0,0 +1,18 @@ + + + +title + + + +

title

+ + + + + + +
foo999
+ + + diff --git a/bench/tt.html b/bench/tt.html new file mode 100644 index 0000000..577d28d --- /dev/null +++ b/bench/tt.html @@ -0,0 +1,20 @@ + + + +[% title | html %] + + + +

[% title | html %]

+ + + + [% FOREACH item IN list %] + + + [% END # FOREACH %] + +
[% item.name | html %][% item.count | html %]
+ + +