]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
and added genshi to rwbench too. want to see how much the GSOC improves performance :)
authorArmin Ronacher <armin.ronacher@active-4.com>
Sun, 25 May 2008 18:51:09 +0000 (20:51 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Sun, 25 May 2008 18:51:09 +0000 (20:51 +0200)
--HG--
branch : trunk

examples/rwbench/django/index.html
examples/rwbench/genshi/helpers.html [new file with mode: 0644]
examples/rwbench/genshi/index.html [new file with mode: 0644]
examples/rwbench/genshi/layout.html [new file with mode: 0644]
examples/rwbench/jinja/index.html
examples/rwbench/mako/index.html
examples/rwbench/rwbench.py

index b5da4ccda92c7606445481898c0ef98fc7429a12..6f620bb2c04f555b9771ad6a776a54f8b2004e59 100644 (file)
@@ -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 (file)
index 0000000..ecc6dc4
--- /dev/null
@@ -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 (file)
index 0000000..70f697d
--- /dev/null
@@ -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 (file)
index 0000000..b12aec4
--- /dev/null
@@ -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>
index 833811303ad8547729817d4ad48eabb624e4ea1a..b006d0565e1a0405f52cd27d852240e66c95cd13 100644 (file)
@@ -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>
index dde6c8ee3b336f57b7b88834faa9bf96d3caf6b4..c4c6303246e3649a182d5da6de05732deb83b147 100644 (file)
@@ -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>
index 4714da472c1cb2d9214379e5e266cd822fa487b2..1bde05694786aba2990c56a6d8678b8cc01eac4c 100644 (file)
@@ -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)