- 论坛徽章:
- 1
|
我认为认为模板的效率在一般的站点不太会成为速度瓶颈。所以一直用了N年Template-Toolkit。之前还用过Mason和HTML::Template,最后感觉Template-Toolkit更适合我。
直到,发现了小日本的这个http://xslate.org/benchmark.html。为此,去年换了Xslate。再后来是前两周开始用Mojolicious,作者喜欢发明轮子,所以就有了Mojo::Template。(这里顺便一提,作者在解释为什么要重新发明轮子的时候这样说“Because we can make them rounder.”这说法够拽,以后我就和经理这么说。)
我测试了一下Text::Xslate和Mojo::Template,代码如下:- use Mojo::Template;
- use Text::Xslate;
- use Benchmark qw/timethese cmpthese/;
- my $result = timethese(
- 10000,
- {
- mojo_template => sub {
- my $mt = Mojo::Template->new;
- $mt->render('Hello World');
- },
- text_xslate => sub {
- my $tx = Text::Xslate->new;
- $tx->render_string('Hello World');
- }
- }
- );
- cmpthese($result);
复制代码 在一个比较老的双处理器(一共4核)的机器上的到下面的结果:- Benchmark: timing 10000 iterations of mojo_template, text_xslate...
- mojo_template: 3 wallclock secs ( 2.48 usr + 0.00 sys = 2.48 CPU) @ 4032.26/s (n=10000)
- text_xslate: 21 wallclock secs (20.77 usr + 0.04 sys = 20.81 CPU) @ 480.54/s (n=10000)
- Rate text_xslate mojo_template
- text_xslate 481/s -- -88%
- mojo_template 4032/s 739% --
复制代码 后来看到http://xslate.org/benchmark.html提到xslate要在好的服务器上测试才能发挥性能。
好,换一个双处理器24核的新机器上再测,结果:- Benchmark: timing 10000 iterations of mojo_template, text_xslate...
- mojo_template: 2 wallclock secs ( 1.84 usr + 0.00 sys = 1.84 CPU) @ 5434.78/s (n=10000)
- text_xslate: 13 wallclock secs (13.22 usr + 0.02 sys = 13.24 CPU) @ 755.29/s (n=10000)
- Rate text_xslate mojo_template
- text_xslate 755/s -- -86%
- mojo_template 5435/s 620% --
复制代码 看来是时候换模板了。也省得用我用Mojolicious还得通过plugin来支持Xslate并使用TT的语法。只是还得花时间看一下Mojo::Template的语法。
几周前我这里用的从模块到webserver,很大一部分都是日本制造。等我把模板也换了,我这里就再没有日本制造的任何东西了。
|
|