typester (owner)

Revisions

gist: 156998 Download_button fork
public
Public Clone URL: git://gist.github.com/156998.git
Embed All Files: show embed
0-result #
1
2
3
4
5
               Rate mtf tenjin mtf_reuse tenjin_reuse
mtf 426/s -- -69% -70% -83%
tenjin 1351/s 218% -- -5% -45%
mtf_reuse 1429/s 236% 6% -- -41%
tenjin_reuse 2439/s 473% 80% 71% --
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/usr/bin/env perl
 
use strict;
use warnings;
use Benchmark qw/cmpthese/;
 
use Tenjin;
use Text::MicroTemplate::File;
 
my $tenjin = Tenjin::Engine->new;
my $mtf = Text::MicroTemplate::File->new( use_cache => 1 );
 
my $context = context();
my ($output_tenjin, $output_mt);
 
cmpthese(1000, {
    tenjin => sub {
        my $tenjin = Tenjin::Engine->new;
        $output_tenjin = $tenjin->render('template.tenjin', $context);
    },
    tenjin_reuse => sub {
        $output_tenjin = $tenjin->render('template.tenjin', $context);
    },
    mtf => sub {
        my $mtf = Text::MicroTemplate::File->new;
        $output_mt = $mtf->render_file('template.mt', $context)->as_string;
    },
    mtf_reuse => sub {
        $output_mt = $mtf->render_file('template.mt', $context)->as_string;
    },
});
 
unless ($output_mt eq $output_tenjin) {
    die 'Output is not same!';
}
 
sub context {
    return {
        list => [
            { 'name' => 'Adobe Systems',
                'name2' => 'Adobe Systems Inc.',
                'url' => 'http://www.adobe.com',
                'symbol' => 'ADBE',
                'price' => 39.26,
                'change' => 0.13,
                'ratio' => 0.33,
            },
            { 'name' => 'Advanced Micro Devices',
                'name2' => 'Advanced Micro Devices Inc.',
                'url' => 'http://www.amd.com',
                'symbol' => 'AMD',
                'price' => 16.22,
                'change' => 0.17,
                'ratio' => 1.06,
            },
            { 'name' => 'Amazon.com',
                'name2' => 'Amazon.com Inc',
                'url' => 'http://www.amazon.com',
                'symbol' => 'AMZN',
                'price' => 36.85,
                'change' => -0.23,
                'ratio' => -0.62,
            },
            { 'name' => 'Apple',
                'name2' => 'Apple Inc.',
                'url' => 'http://www.apple.com',
                'symbol' => 'AAPL',
                'price' => 85.38,
                'change' => -0.87,
                'ratio' => -1.01,
            },
            { 'name' => 'BEA Systems',
                'name2' => 'BEA Systems Inc.',
                'url' => 'http://www.bea.com',
                'symbol' => 'BEAS',
                'price' => 12.46,
                'change' => 0.09,
                'ratio' => 0.73,
            },
            { 'name' => 'CA',
                'name2' => 'CA, Inc.',
                'url' => 'http://www.ca.com',
                'symbol' => 'CA',
                'price' => 24.66,
                'change' => 0.38,
                'ratio' => 1.57,
            },
            { 'name' => 'Cisco Systems',
                'name2' => 'Cisco Systems Inc.',
                'url' => 'http://www.cisco.com',
                'symbol' => 'CSCO',
                'price' => 26.35,
                'change' => 0.13,
                'ratio' => 0.5,
            },
            { 'name' => 'Dell',
                'name2' => 'Dell Corp.',
                'url' => 'http://www.dell.com/',
                'symbol' => 'DELL',
                'price' => 23.73,
                'change' => -0.42,
                'ratio' => -1.74,
            },
            { 'name' => 'eBay',
                'name2' => 'eBay Inc.',
                'url' => 'http://www.ebay.com',
                'symbol' => 'EBAY',
                'price' => 31.65,
                'change' => -0.8,
                'ratio' => -2.47,
            },
            { 'name' => 'Google',
                'name2' => 'Google Inc.',
                'url' => 'http://www.google.com',
                'symbol' => 'GOOG',
                'price' => 495.84,
                'change' => 7.75,
                'ratio' => 1.59,
            },
            { 'name' => 'Hewlett-Packard',
                'name2' => 'Hewlett-Packard Co.',
                'url' => 'http://www.hp.com',
                'symbol' => 'HPQ',
                'price' => 41.69,
                'change' => -0.02,
                'ratio' => -0.05,
            },
            { 'name' => 'IBM',
                'name2' => 'International Business Machines Corp.',
                'url' => 'http://www.ibm.com',
                'symbol' => 'IBM',
                'price' => 97.45,
                'change' => -0.06,
                'ratio' => -0.06,
            },
            { 'name' => 'Intel',
                'name2' => 'Intel Corp.',
                'url' => 'http://www.intel.com',
                'symbol' => 'INTC',
                'price' => 20.53,
                'change' => -0.07,
                'ratio' => -0.34,
            },
            { 'name' => 'Juniper Networks',
                'name2' => 'Juniper Networks, Inc',
                'url' => 'http://www.juniper.net/',
                'symbol' => 'JNPR',
                'price' => 18.96,
                'change' => 0.5,
                'ratio' => 2.71,
            },
            { 'name' => 'Microsoft',
                'name2' => 'Microsoft Corp',
                'url' => 'http://www.microsoft.com',
                'symbol' => 'MSFT',
                'price' => 30.6,
                'change' => 0.15,
                'ratio' => 0.49,
            },
            { 'name' => 'Oracle',
                'name2' => 'Oracle Corp.',
                'url' => 'http://www.oracle.com',
                'symbol' => 'ORCL',
                'price' => 17.15,
                'change' => 0.17,
                'ratio' => 1.0,
            },
            { 'name' => 'SAP',
                'name2' => 'SAP AG',
                'url' => 'http://www.sap.com',
                'symbol' => 'SAP',
                'price' => 46.2,
                'change' => -0.16,
                'ratio' => -0.35,
            },
            { 'name' => 'Seagate Technology',
                'name2' => 'Seagate Technology',
                'url' => 'http://www.seagate.com/',
                'symbol' => 'STX',
                'price' => 27.35,
                'change' => -0.36,
                'ratio' => -1.3,
            },
            { 'name' => 'Sun Microsystems',
                'name2' => 'Sun Microsystems Inc.',
                'url' => 'http://www.sun.com',
                'symbol' => 'SUNW',
                'price' => 6.33,
                'change' => -0.01,
                'ratio' => -0.16,
            },
            { 'name' => 'Yahoo',
                'name2' => 'Yahoo! Inc.',
                'url' => 'http://www.yahoo.com',
                'symbol' => 'YHOO',
                'price' => 28.04,
                'change' => -0.17,
                'ratio' => -0.6,
            },
        ]
    };
}
 
 
template.mt #
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
? my $list = $_[0]->{list};
   <tbody>
? my $n = 0;
? for my $itemref (@$list) {
? my %item = %$itemref;
? $n += 1;
    <tr class="<?= $n % 2 == 0 ? 'even' : 'odd' ?>">
     <td style="text-align: center"><?= $n ?></td>
     <td>
      <a href="/stocks/<?= $item{'symbol'} ?>"><?= $item{'symbol'} ?></a>
     </td>
     <td>
      <a href="<?= $item{'url'} ?>"><?= $item{'name'} ?></a>
     </td>
     <td>
      <strong><?= $item{'price'} ?></strong>
     </td>
? if ($item{'change'} < 0.0) {
     <td class="minus"><?= $item{'change'} ?></td>
     <td class="minus"><?= $item{'ratio'} ?></td>
? } else {
     <td><?= $item{'change'} ?></td>
     <td><?= $item{'ratio'} ?></td>
? }
    </tr>
? }
   </tbody>
 
template.tenjin #
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
<?pl #@ARGS list ?>
   <tbody>
<?pl
my $n = 0;
for my $itemref (@$list) {
    my %item = %$itemref;
    $n += 1;
 ?>
    <tr class="[== $n % 2 == 0 ? 'even' : 'odd' =]">
     <td style="text-align: center">[== $n =]</td>
     <td>
      <a href="/stocks/[== $item{'symbol'} =]">[== $item{'symbol'} =]</a>
     </td>
     <td>
      <a href="[== $item{'url'} =]">[== $item{'name'} =]</a>
     </td>
     <td>
      <strong>[== $item{'price'} =]</strong>
     </td>
    <?pl if ($item{'change'} < 0.0) { ?>
     <td class="minus">[== $item{'change'} =]</td>
     <td class="minus">[== $item{'ratio'} =]</td>
    <?pl } else { ?>
     <td>[== $item{'change'} =]</td>
     <td>[== $item{'ratio'} =]</td>
    <?pl } ?>
    </tr>
<?pl
}
 ?>
   </tbody>