Text::ClearSilver のベンチマークをとってみた
【追記】ごめん。うそなんだ。。。本当は一番はやいのが cs です。
id:gfx が clearsilver binding をかいたということなので、ベンチマークをとってみた。
結果をみてみると、意外なことに Text::ClearSilver の方が TT より遅いということがわかった。なんでだろう。
5.010001 linux at foo.pl line 22. Template: 2.22 Text::MicroTemplate: 0.11 Text::ClearSilver: 0.10.5.0 (warning: too few iterations for a reliable count) Rate cs tt mt cs 1139/s -- -60% -96% tt 2833/s 149% -- -91% mt 32258/s 2732% 1039% --
ベンチマークスクリプトは以下のとおり。
use Text::ClearSilver; use Text::MicroTemplate; use Template; use Text::MicroTemplate 'render_mt'; use Benchmark ':all'; my $cs = Text::ClearSilver->new( # core configuration VarEscapeMode => 'html', # html,js,url, or none TagStart => 'cs', # <?cs ... > # extended configuratin load_path => [qw(/path/to/template)], dataset => { common_foo => 'value' }, ); $cs->register_function( lcfirst => sub { lcfirst $_[0] } ); my $tt = Template->new(); warn "$] $^O"; warn "Template: $Template::VERSION\n"; warn "Text::MicroTemplate: $Text::MicroTemplate::VERSION\n"; warn "Text::ClearSilver: $Text::ClearSilver::VERSION\n"; #arn _cs(); #arn _tt(); #arn _mt(); cmpthese( '10000' => { 'cs' => \&_cs, 'tt' => \&_tt, 'mt' => \&_mt, }, ); sub _cs { $cs->process( \q{<?cs var:lcfirst(foo) ?>}, { foo => 'bar' }, \my $out ); $out; } sub _tt { $tt->process(\q{[% foo | lcfirst %]}, {foo => 'bar'}, \my $out) or die; $out; } sub _mt { render_mt(q{<?= lcfirst $_[0] ?>}, 'bar'); }
なお、benchmark/simple.pl がうごかなかった。