annotate examples/bench/bigtable.py @ 319:bab19496d4fa trunk

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