Browse files

Adding benchmarking code.

Current status: very slow
$ perl -Ilib benchmark.pl
Benchmark: timing 1000000 iterations of Complex Templates, Plain String (No Interpolation), Recursive Templates, Self-Parsing, Simple Interpolation...
Complex Templates: 757 wallclock secs (725.60 usr +  1.54 sys = 727.14 CPU) @ 1375.25/s (n=1000000)
Plain String (No Interpolation): 88 wallclock secs (84.43 usr +  0.16 sys = 84.59 CPU) @ 11821.73/s (n=1000000)
Recursive Templates: 345 wallclock secs (331.01 usr +  0.63 sys = 331.64 CPU) @ 3015.32/s (n=1000000)
Self-Parsing: 1834 wallclock secs (1751.65 usr + 32.21 sys = 1783.86 CPU) @ 560.58/s (n=1000000)
Simple Interpolation: 743 wallclock secs (729.42 usr +  1.02 sys = 730.44 CPU) @ 1369.04/s (n=1000000)
  • Loading branch information...
1 parent d877597 commit 826843cb773452d7c140d72a4d8a002a9dbc9d76 @pvande committed Jan 6, 2011
Showing with 108 additions and 0 deletions.
  1. +108 −0 benchmark.pl
View
108 benchmark.pl
@@ -0,0 +1,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
+});

0 comments on commit 826843c

Please sign in to comment.