Mercurial > genshi > genshi-test
annotate examples/bench/bigtable.py @ 275:7f24dd6fb904
Integrated `HTMLFormFiller` filter initially presented as a [wiki:FormFilling#Usingatemplatefilter recipe].
author | cmlenz |
---|---|
date | Sun, 01 Oct 2006 22:54:57 +0000 |
parents | 7a426ab6407a |
children | 2aa99bf95d84 577883286556 |
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 | 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 |
230 | 14 from genshi.builder import tag |
233
7a426ab6407a
* Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents:
230
diff
changeset
|
15 from genshi.template import MarkupTemplate |
97
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 |
233
7a426ab6407a
* Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents:
230
diff
changeset
|
41 genshi_tmpl = MarkupTemplate(""" |
230 | 42 <table xmlns:py="http://genshi.edgewall.org/"> |
97
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 |
233
7a426ab6407a
* Added implementation of a simple text-based template engine. Closes #47.
cmlenz
parents:
230
diff
changeset
|
49 genshi_tmpl2 = MarkupTemplate(""" |
230 | 50 <table xmlns:py="http://genshi.edgewall.org/">$table</table> |
97
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 |
230 | 67 def test_genshi(): |
68 """Genshi template""" | |
69 stream = genshi_tmpl.generate(table=table) | |
123
93bbdcf9428b
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
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
71 |
230 | 72 def test_genshi_builder(): |
73 """Genshi template + tag builder""" | |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
74 stream = tag.TABLE([ |
33fee66e0e8a
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()]) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
76 for row in table |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
77 ]).generate() |
230 | 78 stream = genshi_tmpl2.generate(table=stream) |
123
93bbdcf9428b
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
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
80 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
81 def test_builder(): |
230 | 82 """Genshi tag builder""" |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
83 stream = tag.TABLE([ |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
84 tag.tr([ |
33fee66e0e8a
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() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
86 ]) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
87 for row in table |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
88 ]).generate() |
123
93bbdcf9428b
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
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
90 |
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
|
91 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
|
92 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
|
93 <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
|
94 <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
|
95 <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
|
96 </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
|
97 </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
|
98 """) |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
99 |
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
|
100 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
|
101 <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
|
102 """) |
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 |
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 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
|
105 """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
|
106 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
|
107 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
|
108 |
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 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
|
110 """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
|
111 _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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
119 def test_et(): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
120 """ElementTree""" |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
121 _table = et.Element('table') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
122 for row in table: |
33fee66e0e8a
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') |
33fee66e0e8a
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(): |
33fee66e0e8a
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) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
126 et.tostring(_table) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
127 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
128 def test_cet(): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
129 """cElementTree""" |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
130 _table = cet.Element('table') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
131 for row in table: |
33fee66e0e8a
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') |
33fee66e0e8a
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(): |
33fee66e0e8a
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) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
135 cet.tostring(_table) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
136 |
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
|
137 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
|
138 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
|
139 """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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 |
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
|
145 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
|
146 cs.parseStr(""" |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
147 <table><?cs |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
148 each:row=rows |
33fee66e0e8a
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 |
33fee66e0e8a
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 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
151 ?></tr><?cs /each?> |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
152 </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
|
153 cs.render() |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
154 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
155 |
33fee66e0e8a
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 | 157 tests = ['test_builder', 'test_genshi', 'test_genshi_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
|
158 '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
|
159 'test_django'] |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
160 if which: |
33fee66e0e8a
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) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
162 |
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
|
163 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
|
164 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
|
165 stmt='%s()' % test) |
33fee66e0e8a
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 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
167 |
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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
174 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
175 if __name__ == '__main__': |
33fee66e0e8a
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] != '-'] |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
177 |
33fee66e0e8a
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: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
179 import hotshot, hotshot.stats |
33fee66e0e8a
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") |
33fee66e0e8a
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) |
33fee66e0e8a
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") |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
183 stats.strip_dirs() |
33fee66e0e8a
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') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
185 stats.print_stats() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
186 else: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
187 run(which) |