forked from yanick/Template-Mustache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.pl
108 lines (106 loc) · 4.02 KB
/
benchmark.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/perl
use Benchmark;
use Template::Mustache;
timethese(1_000_000,{
"Plain String (No Interpolation)" => <<' PERL',
Template::Mustache->render(<<' MUSTACHE');
I am the very model of a modern Major-General,
I've information vegetable, animal, and mineral,
I know the kings of England, and I quote the fights historical
From Marathon to Waterloo, in order categorical;
I'm very well acquainted, too, with matters mathematical,
I understand equations, both the simple and quadratical,
About binomial theorem I'm teeming with a lot o' news,
With many cheerful facts about the square of the hypotenuse.
MUSTACHE
PERL
"Simple Interpolation" => <<' PERL',
my $data = {
title => 'Major-General',
info => [
{ kind => 'vegetable' },
{ kind => 'animal' },
{ kind => 'mineral', conjunction => 1 },
],
country => 'England',
order => 'categorical',
degree => 'very well',
advanced_topic => 'binomial theorem',
gerund => 'teeming',
subject => 'the square of the hypotenuse',
};
Template::Mustache->render(<<' MUSTACHE', $data);
I am the very model of a modern {{title}},
I've information {{#info}}{{#conjunction}}and {{/conjunction}}{{kind}},{{/info}}
I know the kings of {{country}}, and I quote the fights historical
From Marathon to Waterloo, in order {{order}};
I'm {{degree}} acquainted, too, with matters mathematical,
I understand equations, both the simple and quadratical,
About {{advanced_topic}} I'm {{gerund}} with a lot o' news,
With many cheerful facts about {{subject}}.
MUSTACHE
PERL
"Complex Templates" => <<' PERL',
my $data = {
what => "the song that doesn't end",
who => "Some people",
why => "Just because",
last => 0,
};
Template::Mustache->render(<<' MUSTACHE', $data);
{{^last}}
This is {{what}},
Yes, it goes on and on my friend;
{{who}} started singing it,
Not knowing what it was --
And they'll continue singing it forever
{{why}}
This is {{what}},
Yes, it goes on and on my friend;
{{who}} started singing it,
Not knowing what it was --
And they'll continue singing it forever
{{why}}
This is {{what}},
Yes, it goes on and on my friend;
{{who}} started singing it,
Not knowing what it was --
And they'll continue singing it forever
{{why}}
{{/last}}
{{#last}}
This is {{what}},
Until I'm done.
{{/last}}
MUSTACHE
PERL
"Recursive Templates" => <<' PERL',
my $repetitions = 1000;
my $data = {
what => "the song that doesn't end",
who => "Some people",
why => "Just because",
last => sub { $repetitions-- },
};
my $partials = {
verse => "This is {{what}},
Yes, it goes on and on my friend;
{{who}} started singing it,
Not knowing what it was --
And they'll continue singing it forever
{{why}}
{{^last}}{{> verse}}{{/last}}",
};
Template::Mustache->render(<<' MUSTACHE', $data, $partials);
{{> verse}}
This is {{what}},
Until I'm done.
MUSTACHE
PERL
"Self-Parsing" => <<' PERL',
open FILE, 'benchmark.pl';
sysread(FILE, my $template, -s FILE);
close FILE;
Template::Mustache->render($template);
PERL
});