Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,4 @@ | |
^\. | ||
^t/9\d_.*\.t | ||
\.sw[po]$ | ||
^bench/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}, | ||
})); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |