annotate examples/bench/bigtable.py @ 233:88ec2b306296 trunk

* Added implementation of a simple text-based template engine. Closes #47. * Added upgrade instructions.
author cmlenz
date Tue, 12 Sep 2006 13:30:26 +0000
parents 84168828b074
children bab19496d4fa eb2ef86a2cec
rev   line source
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
2 # Template language benchmarks
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
3 #
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
4 # Objective: Generate a 1000x10 HTML table as fast as possible.
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
5 #
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
6 # Author: Jonas Borgström <jonas@edgewall.com>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
7
117
f96b04b0db96 Merged [141].
cmlenz
parents: 97
diff changeset
8 import cgi
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
9 import sys
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
10 import timeit
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
11
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
12 import cElementTree as cet
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
13 from elementtree import ElementTree as et
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
14 from genshi.builder import tag
233
88ec2b306296 * Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents: 230
diff changeset
15 from genshi.template import MarkupTemplate
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
16 import neo_cgi
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
17 import neo_cs
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
18 import neo_util
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
19
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
20 try:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
21 import neo_cgi, neo_cs, neo_util
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
22 except ImportError:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
23 neo_cgi = None
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
24
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
25 try:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
26 import kid
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
27 except ImportError:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
28 kid = None
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
29
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
30 try:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
31 from django.conf import settings
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
32 settings.configure()
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
33 from django.template import Context as DjangoContext
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
34 from django.template import Template as DjangoTemplate
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
35 except ImportError:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
36 DjangoContext = DjangoTemplate = None
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
37
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
38 table = [dict(a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
39 for x in range(1000)]
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
40
233
88ec2b306296 * Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents: 230
diff changeset
41 genshi_tmpl = MarkupTemplate("""
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
42 <table xmlns:py="http://genshi.edgewall.org/">
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
43 <tr py:for="row in table">
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
44 <td py:for="c in row.values()" py:content="c"/>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
45 </tr>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
46 </table>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
47 """)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
48
233
88ec2b306296 * Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents: 230
diff changeset
49 genshi_tmpl2 = MarkupTemplate("""
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
50 <table xmlns:py="http://genshi.edgewall.org/">$table</table>
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
51 """)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
52
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
53 if DjangoTemplate:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
54 django_tmpl = DjangoTemplate("""
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
55 <table>
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
56 {% for row in table %}
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
57 <tr>{% for col in row.values %}{{ col|escape }}{% endfor %}</tr>
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
58 {% endfor %}
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
59 </table>
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
60 """)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
61
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
62 def test_django():
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
63 """Djange template"""
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
64 context = DjangoContext({'table': table})
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
65 django_tmpl.render(context)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
66
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
67 def test_genshi():
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
68 """Genshi template"""
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
69 stream = genshi_tmpl.generate(table=table)
123
10279d2eeec9 Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents: 117
diff changeset
70 stream.render('html', strip_whitespace=False)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
71
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
72 def test_genshi_builder():
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
73 """Genshi template + tag builder"""
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
74 stream = tag.TABLE([
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
75 tag.tr([tag.td(c) for c in row.values()])
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
76 for row in table
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
77 ]).generate()
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
78 stream = genshi_tmpl2.generate(table=stream)
123
10279d2eeec9 Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents: 117
diff changeset
79 stream.render('html', strip_whitespace=False)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
80
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
81 def test_builder():
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
82 """Genshi tag builder"""
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
83 stream = tag.TABLE([
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
84 tag.tr([
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
85 tag.td(c) for c in row.values()
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
86 ])
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
87 for row in table
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
88 ]).generate()
123
10279d2eeec9 Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents: 117
diff changeset
89 stream.render('html', strip_whitespace=False)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
90
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
91 if kid:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
92 kid_tmpl = kid.Template("""
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
93 <table xmlns:py="http://purl.org/kid/ns#">
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
94 <tr py:for="row in table">
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
95 <td py:for="c in row.values()" py:content="c"/>
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
96 </tr>
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
97 </table>
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
98 """)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
99
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
100 kid_tmpl2 = kid.Template("""
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
101 <html xmlns:py="http://purl.org/kid/ns#">$table</html>
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
102 """)
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
103
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
104 def test_kid():
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
105 """Kid template"""
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
106 kid_tmpl.table = table
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
107 kid_tmpl.serialize(output='html')
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
108
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
109 def test_kid_et():
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
110 """Kid template + cElementTree"""
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
111 _table = cet.Element('table')
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
112 for row in table:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
113 td = cet.SubElement(_table, 'tr')
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
114 for c in row.values():
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
115 cet.SubElement(td, 'td').text=str(c)
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
116 kid_tmpl2.table = _table
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
117 kid_tmpl2.serialize(output='html')
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
118
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
119 def test_et():
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
120 """ElementTree"""
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
121 _table = et.Element('table')
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
122 for row in table:
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
123 tr = et.SubElement(_table, 'tr')
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
124 for c in row.values():
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
125 et.SubElement(tr, 'td').text=str(c)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
126 et.tostring(_table)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
127
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
128 def test_cet():
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
129 """cElementTree"""
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
130 _table = cet.Element('table')
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
131 for row in table:
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
132 tr = cet.SubElement(_table, 'tr')
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
133 for c in row.values():
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
134 cet.SubElement(tr, 'td').text=str(c)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
135 cet.tostring(_table)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
136
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
137 if neo_cgi:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
138 def test_clearsilver():
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
139 """ClearSilver"""
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
140 hdf = neo_util.HDF()
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
141 for i, row in enumerate(table):
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
142 for j, c in enumerate(row.values()):
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
143 hdf.setValue("rows.%d.cell.%d" % (i, j), cgi.escape(str(c)))
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
144
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
145 cs = neo_cs.CS(hdf)
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
146 cs.parseStr("""
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
147 <table><?cs
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
148 each:row=rows
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
149 ?><tr><?cs each:c=row.cell
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
150 ?><td><?cs var:c ?></td><?cs /each
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
151 ?></tr><?cs /each?>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
152 </table>""")
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
153 cs.render()
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
154
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
155
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
156 def run(which=None, number=10):
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
157 tests = ['test_builder', 'test_genshi', 'test_genshi_builder', 'test_kid',
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
158 'test_kid_et', 'test_et', 'test_cet', 'test_clearsilver',
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
159 'test_django']
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
160 if which:
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
161 tests = filter(lambda n: n[5:] in which, tests)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
162
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
163 for test in [t for t in tests if hasattr(sys.modules[__name__], t)]:
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
164 t = timeit.Timer(setup='from __main__ import %s;' % test,
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
165 stmt='%s()' % test)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
166 time = t.timeit(number=number) / number
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
167
130
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
168 if time < 0.00001:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
169 result = ' (not installed?)'
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
170 else:
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
171 result = '%16.2f ms' % (1000 * time)
6edc71acb642 Added Django to the [wiki:MarkupPerformance#bigtablebenchmark bigtable benchmark], based on patch contributed by Simon Willison (#23). Also, changed the benchmark so that Clearsilver, Kid, and Django are not required to run the benchmark.
cmlenz
parents: 123
diff changeset
172 print '%-35s %s' % (getattr(sys.modules[__name__], test).__doc__, result)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
173
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
174
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
175 if __name__ == '__main__':
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
176 which = [arg for arg in sys.argv[1:] if arg[0] != '-']
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
177
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
178 if '-p' in sys.argv:
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
179 import hotshot, hotshot.stats
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
180 prof = hotshot.Profile("template.prof")
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
181 benchtime = prof.runcall(run, which, number=1)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
182 stats = hotshot.stats.load("template.prof")
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
183 stats.strip_dirs()
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
184 stats.sort_stats('time', 'calls')
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
185 stats.print_stats()
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
186 else:
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
187 run(which)
Copyright (C) 2012-2017 Edgewall Software