annotate examples/bench/bigtable.py @ 367:eb2ef86a2cec stable-0.3.x

Ported [409] to 0.3.x.
author cmlenz
date Wed, 22 Nov 2006 20:53:30 +0000
parents 88ec2b306296
children
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
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
12 from genshi.builder import tag
233
88ec2b306296 * Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents: 230
diff changeset
13 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
14 import neo_cgi
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
15 import neo_cs
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
16 import neo_util
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
17
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
18 try:
367
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
19 from elementtree import ElementTree as et
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
20 except ImportError:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
21 et = None
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
22
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
23 try:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
24 import cElementTree as cet
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
25 except ImportError:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
26 cet = None
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
27
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
28 try:
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
29 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
30 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
31 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
32
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 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
34 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
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 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
37
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
38 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
39 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
40 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
41 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
42 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
43 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
44 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
45
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
46 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
47 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
48
233
88ec2b306296 * Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents: 230
diff changeset
49 genshi_tmpl = MarkupTemplate("""
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
50 <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
51 <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
52 <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
53 </tr>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
54 </table>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
55 """)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
56
233
88ec2b306296 * Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents: 230
diff changeset
57 genshi_tmpl2 = MarkupTemplate("""
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
58 <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
59 """)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
60
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
61 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
62 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
63 <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
64 {% 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
65 <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
66 {% 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
67 </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
68 """)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
69
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
70 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
71 """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
72 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
73 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
74
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
75 def test_genshi():
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
76 """Genshi template"""
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
77 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
78 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
79
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
80 def test_genshi_builder():
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
81 """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
82 stream = tag.TABLE([
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
83 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
84 for row in table
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
85 ]).generate()
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
86 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
87 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
88
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
89 def test_builder():
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
90 """Genshi tag builder"""
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
91 stream = tag.TABLE([
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
92 tag.tr([
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
93 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
94 ])
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
95 for row in table
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
96 ]).generate()
123
10279d2eeec9 Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents: 117
diff changeset
97 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
98
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
99 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
100 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
101 <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
102 <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
103 <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
104 </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
105 </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
106 """)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
107
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
108 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
109 <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
110 """)
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
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 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
113 """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
114 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
115 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
116
367
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
117
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
118 if cet:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
119 def test_kid_et():
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
120 """Kid template + cElementTree"""
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
121 _table = cet.Element('table')
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
122 for row in table:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
123 td = cet.SubElement(_table, 'tr')
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
124 for c in row.values():
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
125 cet.SubElement(td, 'td').text=str(c)
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
126 kid_tmpl2.table = _table
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
127 kid_tmpl2.serialize(output='html')
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
128
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
129 if et:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
130 def test_et():
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
131 """ElementTree"""
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
132 _table = et.Element('table')
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
133 for row in table:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
134 tr = et.SubElement(_table, 'tr')
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
135 for c in row.values():
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
136 et.SubElement(tr, 'td').text=str(c)
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
137 et.tostring(_table)
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
138
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
139 if cet:
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
140 def test_cet():
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
141 """cElementTree"""
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
142 _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
143 for row in table:
367
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
144 tr = cet.SubElement(_table, 'tr')
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 for c in row.values():
367
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
146 cet.SubElement(tr, 'td').text=str(c)
eb2ef86a2cec Ported [409] to 0.3.x.
cmlenz
parents: 233
diff changeset
147 cet.tostring(_table)
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
148
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
149 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
150 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
151 """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
152 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
153 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
154 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
155 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
156
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
157 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
158 cs.parseStr("""
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
159 <table><?cs
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
160 each:row=rows
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
161 ?><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
162 ?><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
163 ?></tr><?cs /each?>
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
164 </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
165 cs.render()
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
166
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
167
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
168 def run(which=None, number=10):
230
84168828b074 Renamed Markup to Genshi in repository.
cmlenz
parents: 149
diff changeset
169 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
170 '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
171 'test_django']
97
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
172 if which:
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
173 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
174
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
175 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
176 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
177 stmt='%s()' % test)
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
178 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
179
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
180 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
181 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
182 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
183 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
184 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
185
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
186
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
187 if __name__ == '__main__':
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
188 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
189
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
190 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
191 import hotshot, hotshot.stats
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
192 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
193 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
194 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
195 stats.strip_dirs()
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
196 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
197 stats.print_stats()
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
198 else:
ff19219485cc Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
199 run(which)
Copyright (C) 2012-2017 Edgewall Software