Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
Make benchmarks stricter on whitespace and compare output
Browse files Browse the repository at this point in the history
  • Loading branch information
benhoyt committed Sep 21, 2012
1 parent fc22d8e commit df53f02
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 35 deletions.
8 changes: 4 additions & 4 deletions 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')
Expand All @@ -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

Expand Down
15 changes: 8 additions & 7 deletions 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' %}
13 changes: 6 additions & 7 deletions 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' />
31 changes: 22 additions & 9 deletions benchmarks/run_benchmarks.py
Expand Up @@ -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')
Expand Down Expand Up @@ -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__':
Expand Down
7 changes: 3 additions & 4 deletions 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 %}
Expand All @@ -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') }}
8 changes: 4 additions & 4 deletions benchmarks/wheezy/main.tmpl
Expand Up @@ -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.