Skip to content

Commit

Permalink
added benchmark script
Browse files Browse the repository at this point in the history
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%                  --
  • Loading branch information
tomill committed Feb 8, 2010
1 parent e874f01 commit 5c4dbd6
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions MANIFEST.SKIP
Expand Up @@ -14,3 +14,4 @@
^\.
^t/9\d_.*\.t
\.sw[po]$
^bench/
46 changes: 46 additions & 0 deletions 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;
},
}));
21 changes: 21 additions & 0 deletions bench/tm.html
@@ -0,0 +1,21 @@
? my $vars = $_[0];
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><?= $vars->{title} ?></title>
</head>
<body>

<h1><?= $vars->{title} ?></h1>

<table>
<tr>
? for my $item (@{ $vars->{list} || [] }) {
<td><?= $item->{name} ?></td>
<td><?= $item->{count} ?></td>
? }
</tr>
</table>

</body>
</html>
18 changes: 18 additions & 0 deletions bench/ts.html
@@ -0,0 +1,18 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>title</title>
</head>
<body>

<h1>title</h1>

<table class="list">
<tr>
<td class="name">foo</td>
<td class="count">999</td>
</tr>
</table>

</body>
</html>
20 changes: 20 additions & 0 deletions bench/tt.html
@@ -0,0 +1,20 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>[% title | html %]</title>
</head>
<body>

<h1>[% title | html %]</h1>

<table>
<tr>
[% FOREACH item IN list %]
<td>[% item.name | html %]</td>
<td>[% item.count | html %]</td>
[% END # FOREACH %]
</tr>
</table>

</body>
</html>

0 comments on commit 5c4dbd6

Please sign in to comment.