summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2008-05-25 20:51:09 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2008-05-25 20:51:09 +0200
commit0c4f75795f9be2970982dddb59ca10dba7ca1cbd (patch)
tree07e1f5b1143d77ef31c37cf819323e3817aabb01 /examples
parent9cc780391b13226b8a521f214dab18edf388468d (diff)
downloadjinja2-0c4f75795f9be2970982dddb59ca10dba7ca1cbd.tar.gz
and added genshi to rwbench too. want to see how much the GSOC improves performance :)
--HG-- branch : trunk
Diffstat (limited to 'examples')
-rw-r--r--examples/rwbench/django/index.html2
-rw-r--r--examples/rwbench/genshi/helpers.html12
-rw-r--r--examples/rwbench/genshi/index.html41
-rw-r--r--examples/rwbench/genshi/layout.html30
-rw-r--r--examples/rwbench/jinja/index.html2
-rw-r--r--examples/rwbench/mako/index.html2
-rw-r--r--examples/rwbench/rwbench.py9
7 files changed, 94 insertions, 4 deletions
diff --git a/examples/rwbench/django/index.html b/examples/rwbench/django/index.html
index b5da4cc..6f620bb 100644
--- a/examples/rwbench/django/index.html
+++ b/examples/rwbench/django/index.html
@@ -18,7 +18,7 @@
<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>
diff --git a/examples/rwbench/genshi/helpers.html b/examples/rwbench/genshi/helpers.html
new file mode 100644
index 0000000..ecc6dc4
--- /dev/null
+++ b/examples/rwbench/genshi/helpers.html
@@ -0,0 +1,12 @@
+<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>
diff --git a/examples/rwbench/genshi/index.html b/examples/rwbench/genshi/index.html
new file mode 100644
index 0000000..70f697d
--- /dev/null
+++ b/examples/rwbench/genshi/index.html
@@ -0,0 +1,41 @@
+<?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>
diff --git a/examples/rwbench/genshi/layout.html b/examples/rwbench/genshi/layout.html
new file mode 100644
index 0000000..b12aec4
--- /dev/null
+++ b/examples/rwbench/genshi/layout.html
@@ -0,0 +1,30 @@
+<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">
+ &copy; Copyright 2008 by I don't know who.
+ </div>
+ </div>
+ </body>
+ </py:match>
+</html>
diff --git a/examples/rwbench/jinja/index.html b/examples/rwbench/jinja/index.html
index 8338113..b006d05 100644
--- a/examples/rwbench/jinja/index.html
+++ b/examples/rwbench/jinja/index.html
@@ -18,7 +18,7 @@
<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>
diff --git a/examples/rwbench/mako/index.html b/examples/rwbench/mako/index.html
index dde6c8e..c4c6303 100644
--- a/examples/rwbench/mako/index.html
+++ b/examples/rwbench/mako/index.html
@@ -21,7 +21,7 @@
<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>
diff --git a/examples/rwbench/rwbench.py b/examples/rwbench/rwbench.py
index 4714da4..1bde056 100644
--- a/examples/rwbench/rwbench.py
+++ b/examples/rwbench/rwbench.py
@@ -20,6 +20,7 @@ from timeit import Timer
from jinja2 import Environment, FileSystemLoader
from jinja2.utils import generate_lorem_ipsum
from mako.lookup import TemplateLookup
+from genshi.template import TemplateLoader as GenshiTemplateLoader
def dateformat(x):
@@ -29,6 +30,7 @@ def dateformat(x):
jinja_env = Environment(loader=FileSystemLoader(join(ROOT, 'jinja')))
jinja_env.filters['dateformat'] = dateformat
mako_lookup = TemplateLookup(directories=[join(ROOT, 'mako')])
+genshi_loader = GenshiTemplateLoader([join(ROOT, 'genshi')])
class Article(object):
@@ -65,6 +67,7 @@ context = dict(users=users, articles=articles, page_navigation=navigation)
jinja_template = jinja_env.get_template('index.html')
mako_template = mako_lookup.get_template('index.html')
+genshi_template = genshi_loader.load('index.html')
def test_jinja():
@@ -80,9 +83,13 @@ def test_django():
django_template.render(DjangoContext(context))
+def test_genshi():
+ genshi_template.generate(**context).render('html', doctype='html')
+
+
if __name__ == '__main__':
sys.stdout.write('Realworldish Benchmark:\n')
- for test in 'jinja', 'mako', 'django':
+ for test in 'jinja', 'mako', 'django', 'genshi':
t = Timer(setup='from __main__ import test_%s as bench' % test,
stmt='bench()')
sys.stdout.write(' >> %-20s<running>' % test)