Skip to content
Browse files

Make benchmarks stricter on whitespace and compare output

  • Loading branch information...
1 parent fc22d8e commit df53f02a3165e9429485ca9b405bb0694611d982 @benhoyt committed Sep 21, 2012
View
8 benchmarks/cheetah/main.tmpl
@@ -1,7 +1,7 @@
#include $template_dir + "/header.tmpl"
#def paragraph($word)
- <p>This is $word bunch of text just to test a whole bunch of text.</p>
+<p>This is $word bunch of text just to test a whole bunch of text.</p>#slurp
#end def
#filter Filter
$paragraph('a')
@@ -11,12 +11,12 @@ $paragraph('yet another')
#for $entry in $entries:
#if $entry.url
- <h2><a href="$entry.url">$entry.title.title()</a></h2>
+<h2><a href="$entry.url">$entry.title.title()</a></h2>
#else
- <h2>$entry.title.title()</h2>
+<h2>$entry.title.title()</h2>
#end if
#filter Filter
- $entry.html_body
+$entry.html_body
#end filter
#end for
View
15 benchmarks/jinja2/main.tmpl
@@ -1,19 +1,20 @@
{% include 'header.tmpl' %}
+
{% macro paragraph(word) %}
<p>This is {{ word }} bunch of text just to test a whole bunch of text.</p>
-{% endmacro %}
+{%- endmacro %}
{{ paragraph('a') }}
{{ paragraph('another') }}
{{ paragraph('yet another') }}
{% for entry in entries %}
- {% if entry.url %}
- <h2><a href="{{ entry.url }}">{{ entry.title.title() }}</a></h2>
- {% else %}
- <h2>{{ entry.title.title() }}</h2>
- {% endif %}
- {{ entry.html_body|safe }}
+{% if entry.url %}
+<h2><a href="{{ entry.url }}">{{ entry.title.title() }}</a></h2>
+{% else %}
+<h2>{{ entry.title.title() }}</h2>
+{% endif %}
+{{ entry.html_body|safe }}
{% endfor %}
{% include 'footer.tmpl' %}
View
13 benchmarks/mako/main.tmpl
@@ -1,19 +1,18 @@
-<%include file='header.tmpl' />
-
-<%def name="paragraph(word)">
-<p>This is ${word} bunch of text just to test a whole bunch of text.</p>
+<%include file='header.tmpl' />\
+<%def name="paragraph(word)">\
+<p>This is ${word} bunch of text just to test a whole bunch of text.</p>\
</%def>
${paragraph('a')}
${paragraph('another')}
${paragraph('yet another')}
% for entry in entries:
% if entry.url:
- <h2><a href="${entry.url}">${entry.title.title()}</a></h2>
+<h2><a href="${entry.url}">${entry.title.title()}</a></h2>
% else:
- <h2>${entry.title.title()}</h2>
+<h2>${entry.title.title()}</h2>
% endif
- ${entry.html_body|n}
+${entry.html_body|n}
% endfor
<%include file='footer.tmpl' />
View
31 benchmarks/run_benchmarks.py
@@ -108,8 +108,8 @@ def render(self):
class Jinja2(TemplateLanguage):
def __init__(self):
loader = jinja2.FileSystemLoader(rel_dir('jinja2'))
- self.compile_env = jinja2.Environment(loader=loader, autoescape=True, cache_size=0)
- self.render_env = jinja2.Environment(loader=loader, autoescape=True)
+ self.compile_env = jinja2.Environment(loader=loader, autoescape=True, cache_size=0, trim_blocks=True)
+ self.render_env = jinja2.Environment(loader=loader, autoescape=True, trim_blocks=True)
def compile(self):
return self.compile_env.get_template('main.tmpl')
@@ -179,21 +179,34 @@ def render(self):
def main():
- language_classes = sorted((name, cls) for name, cls in globals().items()
- if isinstance(cls, type) and
- issubclass(cls, TemplateLanguage) and
- cls is not TemplateLanguage)
+ language_classes = [(name, cls) for name, cls in globals().items()
+ if isinstance(cls, type) and
+ issubclass(cls, TemplateLanguage) and
+ cls is not TemplateLanguage]
+
+ results = []
+ output = None
for name, cls in language_classes:
language = cls()
timings = language.benchmark()
- print '%.20s %.3f %.3f' % (name, timings['compile'] * 1000, timings['render'] * 1000)
+ results.append((name, timings['compile'], timings['render']))
output_dir = rel_dir('output')
if not os.path.exists(output_dir):
os.makedirs(output_dir)
- with open(os.path.join(output_dir, name.lower() + '.html'), 'w') as f:
+ with open(os.path.join(output_dir, name.lower() + '.html'), 'wb') as f:
language.setup_render()
- f.write(language.render().encode('utf-8'))
+ rendering = language.render().replace('\r\n', '\n')
+ f.write(rendering.encode('utf-8'))
+ if output is None:
+ output = (name, rendering.strip())
+ elif output[1] != rendering.strip():
+ print 'ERROR: output from %s and %s differ' % (name, output[0])
+
+ print 'Engine compile (ms) render (ms)'
+ print '-----------------------------------'
+ for name, compile_time, render_time in sorted(results, key=lambda r: r[2]):
+ print '%-10s %11.3f %12.3f' % (name, compile_time * 1000, render_time * 1000)
if __name__ == '__main__':
View
7 benchmarks/symplate/main.symp
@@ -1,6 +1,5 @@
{% template entries, title %}
{{ !render('header', title) }}
-
{% def paragraph(word): %}
<p>This is {{ word }} bunch of text just to test a whole bunch of text.</p>
{% end def %}
@@ -10,11 +9,11 @@
{% for entry in entries: %}
{% if entry.url: %}
- <h2><a href="{{ entry.url }}">{{ entry.title.title() }}</a></h2>
+<h2><a href="{{ entry.url }}">{{ entry.title.title() }}</a></h2>
{% else: %}
- <h2>{{ entry.title.title() }}</h2>
+<h2>{{ entry.title.title() }}</h2>
{% end if %}
- {{ !entry.html_body }}
+{{ !entry.html_body }}
{% end for %}
{{ !render('footer') }}
View
8 benchmarks/wheezy/main.tmpl
@@ -2,19 +2,19 @@
@include('header.tmpl')
@def paragraph(word):
-<p>This is @word!h bunch of text just to test a whole bunch of text.</p>
+<p>This is @word!h bunch of text just to test a whole bunch of text.</p>\
@end
@paragraph('a')
@paragraph('another')
@paragraph('yet another')
@for entry in entries:
@if entry.url:
- <h2><a href="@entry.url!h">@entry.title.title()!h</a></h2>
+<h2><a href="@entry.url!h">@entry.title.title()!h</a></h2>
@else:
- <h2>@entry.title.title()!h</h2>
+<h2>@entry.title.title()!h</h2>
@end
- @entry.html_body
+@entry.html_body
@end
@include('footer.tmpl')

0 comments on commit df53f02

Please sign in to comment.
Something went wrong with that request. Please try again.