annotate examples/bench/bigtable.py @ 130:aa69c1f34a26

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.
author cmlenz
date Fri, 04 Aug 2006 10:50:24 +0000
parents 93bbdcf9428b
children 7306bf730ff3
rev   line source
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
1 # -*- encoding: utf-8 -*-
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
2 # Template language benchmarks
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
3 #
33fee66e0e8a 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.
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
5 #
33fee66e0e8a 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>
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
7
117
e51b81f1b5d5 Merged [141].
cmlenz
parents: 97
diff changeset
8 import cgi
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
9 import sys
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
10 import timeit
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
11
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
12 import cElementTree as cet
33fee66e0e8a 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
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
14 from markup.builder import tag
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
15 from markup.template import Context, Template
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
16 import neo_cgi
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
17 import neo_cs
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
18 import neo_util
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
19
130
aa69c1f34a26 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:
aa69c1f34a26 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
aa69c1f34a26 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:
aa69c1f34a26 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
aa69c1f34a26 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
aa69c1f34a26 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:
aa69c1f34a26 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
aa69c1f34a26 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:
aa69c1f34a26 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
aa69c1f34a26 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
aa69c1f34a26 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:
aa69c1f34a26 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
aa69c1f34a26 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()
aa69c1f34a26 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
aa69c1f34a26 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
aa69c1f34a26 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:
aa69c1f34a26 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
aa69c1f34a26 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
33fee66e0e8a 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)
33fee66e0e8a 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)]
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
40
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
41 markup_tmpl = Template("""
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
42 <table xmlns:py="http://markup.edgewall.org/">
33fee66e0e8a 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">
33fee66e0e8a 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"/>
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
45 </tr>
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
46 </table>
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
47 """)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
48
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
49 markup_tmpl2 = Template("""
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
50 <table xmlns:py="http://markup.edgewall.org/">$table</table>
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
51 """)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
52
130
aa69c1f34a26 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:
aa69c1f34a26 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("""
aa69c1f34a26 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>
aa69c1f34a26 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 %}
aa69c1f34a26 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>
aa69c1f34a26 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 %}
aa69c1f34a26 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>
aa69c1f34a26 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
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
61
130
aa69c1f34a26 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():
aa69c1f34a26 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"""
aa69c1f34a26 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})
aa69c1f34a26 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
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
66
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
67 def test_markup():
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
68 """Markup template"""
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
69 ctxt = Context(table=table)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
70 stream = markup_tmpl.generate(ctxt)
123
93bbdcf9428b Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents: 117
diff changeset
71 stream.render('html', strip_whitespace=False)
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
72
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
73 def test_markup_builder():
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
74 """Markup template + tag builder"""
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
75 stream = tag.TABLE([
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
76 tag.tr([tag.td(c) for c in row.values()])
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
77 for row in table
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
78 ]).generate()
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
79 ctxt = Context(table=stream)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
80 stream = markup_tmpl2.generate(ctxt)
123
93bbdcf9428b Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents: 117
diff changeset
81 stream.render('html', strip_whitespace=False)
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
82
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
83 def test_builder():
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
84 """Markup tag builder"""
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
85 stream = tag.TABLE([
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
86 tag.tr([
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
87 tag.td(c) for c in row.values()
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
88 ])
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
89 for row in table
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
90 ]).generate()
123
93bbdcf9428b Fix for #18: whitespace in space-sensitive elements such as `<pre>` and `<textarea>` is now preserved.
cmlenz
parents: 117
diff changeset
91 stream.render('html', strip_whitespace=False)
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
92
130
aa69c1f34a26 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 if kid:
aa69c1f34a26 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 kid_tmpl = kid.Template("""
aa69c1f34a26 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 <table xmlns:py="http://purl.org/kid/ns#">
aa69c1f34a26 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 py:for="row in table">
aa69c1f34a26 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 <td py:for="c in row.values()" py:content="c"/>
aa69c1f34a26 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 </tr>
aa69c1f34a26 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 </table>
aa69c1f34a26 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 """)
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
101
130
aa69c1f34a26 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 kid_tmpl2 = kid.Template("""
aa69c1f34a26 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 <html xmlns:py="http://purl.org/kid/ns#">$table</html>
aa69c1f34a26 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 """)
aa69c1f34a26 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
aa69c1f34a26 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 def test_kid():
aa69c1f34a26 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 template"""
aa69c1f34a26 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_tmpl.table = table
aa69c1f34a26 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 kid_tmpl.serialize(output='html')
aa69c1f34a26 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
aa69c1f34a26 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 def test_kid_et():
aa69c1f34a26 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 """Kid template + cElementTree"""
aa69c1f34a26 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 _table = cet.Element('table')
aa69c1f34a26 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 row in table:
aa69c1f34a26 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 td = cet.SubElement(_table, 'tr')
aa69c1f34a26 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 for c in row.values():
aa69c1f34a26 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 cet.SubElement(td, 'td').text=str(c)
aa69c1f34a26 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
118 kid_tmpl2.table = _table
aa69c1f34a26 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
119 kid_tmpl2.serialize(output='html')
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
120
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
121 def test_et():
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
122 """ElementTree"""
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
123 _table = et.Element('table')
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
124 for row in table:
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
125 tr = et.SubElement(_table, 'tr')
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
126 for c in row.values():
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
127 et.SubElement(tr, 'td').text=str(c)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
128 et.tostring(_table)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
129
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
130 def test_cet():
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
131 """cElementTree"""
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
132 _table = cet.Element('table')
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
133 for row in table:
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
134 tr = cet.SubElement(_table, 'tr')
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
135 for c in row.values():
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
136 cet.SubElement(tr, 'td').text=str(c)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
137 cet.tostring(_table)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
138
130
aa69c1f34a26 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 if neo_cgi:
aa69c1f34a26 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 def test_clearsilver():
aa69c1f34a26 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 """ClearSilver"""
aa69c1f34a26 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 hdf = neo_util.HDF()
aa69c1f34a26 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 i, row in enumerate(table):
aa69c1f34a26 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
144 for j, c in enumerate(row.values()):
aa69c1f34a26 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 hdf.setValue("rows.%d.cell.%d" % (i, j), cgi.escape(str(c)))
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
146
130
aa69c1f34a26 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
147 cs = neo_cs.CS(hdf)
aa69c1f34a26 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
148 cs.parseStr("""
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
149 <table><?cs
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
150 each:row=rows
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
151 ?><tr><?cs each:c=row.cell
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
152 ?><td><?cs var:c ?></td><?cs /each
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
153 ?></tr><?cs /each?>
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
154 </table>""")
130
aa69c1f34a26 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 cs.render()
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
156
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
157
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
158 def run(which=None, number=10):
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
159 tests = ['test_builder', 'test_markup', 'test_markup_builder', 'test_kid',
130
aa69c1f34a26 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
160 'test_kid_et', 'test_et', 'test_cet', 'test_clearsilver',
aa69c1f34a26 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
161 'test_django']
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
162 if which:
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
163 tests = filter(lambda n: n[5:] in which, tests)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
164
130
aa69c1f34a26 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 for test in [t for t in tests if hasattr(sys.modules[__name__], t)]:
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
166 t = timeit.Timer(setup='from __main__ import %s;' % test,
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
167 stmt='%s()' % test)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
168 time = t.timeit(number=number) / number
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
169
130
aa69c1f34a26 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 if time < 0.00001:
aa69c1f34a26 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 = ' (not installed?)'
aa69c1f34a26 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 else:
aa69c1f34a26 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
173 result = '%16.2f ms' % (1000 * time)
aa69c1f34a26 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
174 print '%-35s %s' % (getattr(sys.modules[__name__], test).__doc__, result)
97
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
175
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
176
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
177 if __name__ == '__main__':
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
178 which = [arg for arg in sys.argv[1:] if arg[0] != '-']
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
179
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
180 if '-p' in sys.argv:
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
181 import hotshot, hotshot.stats
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
182 prof = hotshot.Profile("template.prof")
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
183 benchtime = prof.runcall(run, which, number=1)
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
184 stats = hotshot.stats.load("template.prof")
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
185 stats.strip_dirs()
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
186 stats.sort_stats('time', 'calls')
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
187 stats.print_stats()
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
188 else:
33fee66e0e8a Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff changeset
189 run(which)
Copyright (C) 2012-2017 Edgewall Software