and added genshi to rwbench too. want to see how much the GSOC improves performance :)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent 9cc7803 · Browse files · 7 files·+94 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+94 added−4 removed
- other:+94 added−4 removed
Provenance
- Commit
0c4f757- Tree
07e1f5b- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
9cc7803
7 files changed+94 added−4 removed
modified:examples/rwbench/django/index.html+1 added-1 removed
16 unmodified lines171819202121222324254 unmodified lines16 unmodified lines <dt>E-Mail</dt> <dd>{% input_field 'email' %}</dd> <dt>URL</dt> <dd>{% input_field 'url' %}</dd> <dt>Comment</dd> <dt>Comment</dt> <dd>{% textarea 'comment' %}</dd> <dt>Captcha</dt> <dd>{% input_field 'captcha' %}</dd> </dl>4 unmodified linesadded:examples/rwbench/genshi/helpers.html+12 added
123456789101112<div xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/" py:strip="">
<py:def function="input_field(name='', value='', type='text')"> <input type="$type" value="$value" name="$name" /> </py:def>
<py:def function="textarea(name, value='', rows=10, cols=40)"> <textarea name="$name" rows="$rows" cols="cols">$value</textarea> </py:def>
</div>added:examples/rwbench/genshi/index.html+41 added
1234567891011121314151617181920212223242526272829303132333435363738394041<?python from rwbench import dateformat?><html xmlns="http://www.w3.org/1999/xhtml" xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:py="http://genshi.edgewall.org/"> <xi:include href="layout.html" /> <xi:include href="helpers.html" /> <head><title>Index Page</title></head> <body> <div class="article" py:for="article in articles"> <py:if test="article.published"> <h2><a href="${article.href}">${article.title}</a></h2> <p class="meta">written by <a href="${article.user.href}" >${article.user.username}</a> on ${dateformat(article.pub_date)}</p> <div class="text">${Markup(article.body)}</div> </py:if> </div> <!-- For a fair and balanced comparison we would have to use a def here that wraps the form data but I don't know what would be the best Genshi equivalent for that. Quite frankly I doubt that this makes sense in Genshi anyways. --> <form action="" method="post"> <dl> <dt>Name</dt> <dd>${input_field('name')}</dd> <dt>E-Mail</dt> <dd>${input_field('email')}</dd> <dt>URL</dt> <dd>${input_field('url')}</dd> <dt>Comment</dt> <dd>${textarea('comment')}</dd> <dt>Captcha</dt> <dd>${input_field('captcha')}</dd> </dl> ${input_field(type='submit', value='Submit')} ${input_field(name='cancel', type='submit', value='Cancel')} </form> </body></html>added:examples/rwbench/genshi/layout.html+30 added
123456789101112131415161718192021222324252627282930<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://genshi.edgewall.org/" > <py:match path="head" once="true"> <head> <title>${select('title/text()')} | RealWorld Benchmark</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> </py:match> <py:match path="body" once="true"> <body> <div class="contents"> <div class="header"> <h1>RealWorld Benchmark</h1> <blockquote><p> A less stupid benchmark for Mako and Jinja2 to get an impression how code changes affect runtime performance. </p></blockquote> </div> <ul class="navigation"> <li py:for="href, caption in page_navigation"><a href="$href">$caption</a></li> </ul> <div class="body"> ${select('*|text()')} </div> <div class="footer"> © Copyright 2008 by I don't know who. </div> </div> </body> </py:match></html>modified:examples/rwbench/jinja/index.html+1 added-1 removed
16 unmodified lines171819202121222324254 unmodified lines16 unmodified lines <dt>E-Mail</dt> <dd>{{ input_field('email') }}</dd> <dt>URL</dt> <dd>{{ input_field('url') }}</dd> <dt>Comment</dd> <dt>Comment</dt> <dd>{{ textarea('comment') }}</dd> <dt>Captcha</dt> <dd>{{ input_field('captcha') }}</dd> </dl>4 unmodified linesmodified:examples/rwbench/mako/index.html+1 added-1 removed
19 unmodified lines202122232424252627283 unmodified lines19 unmodified lines <dt>E-Mail</dt> <dd>${input_field('email')}</dd> <dt>URL</dt> <dd>${input_field('url')}</dd> <dt>Comment</dd> <dt>Comment</dt> <dd>${textarea('comment')}</dd> <dt>Captcha</dt> <dd>${input_field('captcha')}</dd> </dl>3 unmodified linesmodified:examples/rwbench/rwbench.py+8 added-1 removed
18 unmodified lines19 from timeit import Timer20 from jinja2 import Environment, FileSystemLoader21 from jinja2.utils import generate_lorem_ipsum22 from mako.lookup import TemplateLookup23+from genshi.template import TemplateLoader as GenshiTemplateLoader24 25 26 def dateformat(x):27 return x.strftime('%Y-%m-%d')1 unmodified line29 30 jinja_env = Environment(loader=FileSystemLoader(join(ROOT, 'jinja')))31 jinja_env.filters['dateformat'] = dateformat32 mako_lookup = TemplateLookup(directories=[join(ROOT, 'mako')])33+genshi_loader = GenshiTemplateLoader([join(ROOT, 'genshi')])34 35 class Article(object):36 37 def __init__(self, id):28 unmodified lines66 67 68 jinja_template = jinja_env.get_template('index.html')69 mako_template = mako_lookup.get_template('index.html')70+genshi_template = genshi_loader.load('index.html')71 72 73 def test_jinja():74 jinja_template.render(context)7 unmodified lines82 def test_django():83 django_template.render(DjangoContext(context))84 85 86+def test_genshi():87+ genshi_template.generate(**context).render('html', doctype='html')88+89+90 if __name__ == '__main__':91 sys.stdout.write('Realworldish Benchmark:\n')85- for test in 'jinja', 'mako', 'django':92+ for test in 'jinja', 'mako', 'django', 'genshi':93 t = Timer(setup='from __main__ import test_%s as bench' % test,94 stmt='bench()')95 sys.stdout.write(' >> %-20s<running>' % test)96 sys.stdout.flush()1 unmodified line