Mercurial > genshi > genshi-test
annotate examples/bench/basic.py @ 428:540dd825d072
Simplify undefined error message.
author | cmlenz |
---|---|
date | Thu, 22 Mar 2007 16:59:54 +0000 |
parents | 0e6ae0ade606 |
children | 4811658d7ac0 |
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 from cgi import escape |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
2 import os |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
3 from StringIO import StringIO |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
4 import sys |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
5 import timeit |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
6 |
319
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
7 __all__ = ['clearsilver', 'myghty', 'django', 'kid', 'genshi', 'cheetah'] |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
8 |
230 | 9 def genshi(dirname, verbose=False): |
10 from genshi.template import TemplateLoader | |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
11 loader = TemplateLoader([dirname], auto_reload=False) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
12 template = loader.load('template.html') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
13 def render(): |
149
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
136
diff
changeset
|
14 data = dict(title='Just a test', user='joe', |
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
136
diff
changeset
|
15 items=['Number %d' % num for num in range(1, 15)]) |
7306bf730ff3
`Template.generate()` now accepts the context data as keyword arguments, so that you don't have to import the `Context` class every time you want to pass data into a template.
cmlenz
parents:
136
diff
changeset
|
16 return template.generate(**data).render('xhtml') |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
17 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
18 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
19 print render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
20 return render |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
21 |
319
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
22 def myghty(dirname, verbose=False): |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
23 from myghty import interp |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
24 interpreter = interp.Interpreter(component_root=dirname) |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
25 def render(): |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
26 data = dict(title='Just a test', user='joe', |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
27 items=['Number %d' % num for num in range(1, 15)]) |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
28 buffer = StringIO() |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
29 interpreter.execute("template.myt", request_args=data, out_buffer=buffer) |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
30 return buffer.getvalue() |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
31 if verbose: |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
32 print render() |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
33 return render |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
34 |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
35 def cheetah(dirname, verbose=False): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
36 # FIXME: infinite recursion somewhere... WTF? |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
37 from Cheetah.Template import Template |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
38 class MyTemplate(Template): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
39 def serverSidePath(self, path): return os.path.join(dirname, path) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
40 filename = os.path.join(dirname, 'template.tmpl') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
41 template = MyTemplate(file=filename) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
42 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
43 def render(): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
44 template = MyTemplate(file=filename, |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
45 searchList=[{'title': 'Just a test', 'user': 'joe', |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
46 'items': [u'Number %d' % num for num in range(1, 15)]}]) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
47 return template.respond() |
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 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
50 print render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
51 return render |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
52 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
53 def clearsilver(dirname, verbose=False): |
319
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
54 try: |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
55 import neo_cgi |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
56 except ImportError: |
2aa99bf95d84
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
57 return lambda:None |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
58 neo_cgi.update() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
59 import neo_util |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
60 import neo_cs |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
61 def render(): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
62 hdf = neo_util.HDF() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
63 hdf.setValue('hdf.loadpaths.0', dirname) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
64 hdf.setValue('title', escape('Just a test')) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
65 hdf.setValue('user', escape('joe')) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
66 for num in range(1, 15): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
67 hdf.setValue('items.%d' % (num - 1), escape('Number %d' % num)) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
68 cs = neo_cs.CS(hdf) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
69 cs.parseFile('template.cs') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
70 return cs.render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
71 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
72 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
73 print render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
74 return render |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
75 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
76 def django(dirname, verbose=False): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
77 from django.conf import settings |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
78 settings.configure(TEMPLATE_DIRS=[os.path.join(dirname, 'templates')]) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
79 from django import template, templatetags |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
80 from django.template import loader |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
81 templatetags.__path__.append(os.path.join(dirname, 'templatetags')) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
82 tmpl = loader.get_template('template.html') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
83 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
84 def render(): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
85 data = {'title': 'Just a test', 'user': 'joe', |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
86 'items': ['Number %d' % num for num in range(1, 15)]} |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
87 return tmpl.render(template.Context(data)) |
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 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
90 print render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
91 return render |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
92 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
93 def kid(dirname, verbose=False): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
94 import kid |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
95 kid.path = kid.TemplatePath([dirname]) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
96 template = kid.Template(file='template.kid') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
97 def render(): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
98 template = kid.Template(file='template.kid', |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
99 title='Just a test', user='joe', |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
100 items=['Number %d' % num for num in range(1, 15)]) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
101 return template.serialize(output='xhtml') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
102 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
103 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
104 print render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
105 return render |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
106 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
107 def nevow(dirname, verbose=False): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
108 # FIXME: can't figure out the API |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
109 from nevow.loaders import xmlfile |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
110 template = xmlfile('template.xml', templateDir=dirname).load() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
111 def render(): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
112 print template |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
113 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
114 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
115 print render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
116 return render |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
117 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
118 def simpletal(dirname, verbose=False): |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
119 from simpletal import simpleTAL, simpleTALES |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
120 fileobj = open(os.path.join(dirname, 'base.html')) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
121 base = simpleTAL.compileHTMLTemplate(fileobj) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
122 fileobj.close() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
123 fileobj = open(os.path.join(dirname, 'template.html')) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
124 template = simpleTAL.compileHTMLTemplate(fileobj) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
125 fileobj.close() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
126 def render(): |
103
70ec95c8d1ea
benchmark: improved functionality of SimpleTAL example. Thanks to bruno desthuilliers for some tips.
cmlenz
parents:
97
diff
changeset
|
127 ctxt = simpleTALES.Context(allowPythonPath=1) |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
128 ctxt.addGlobal('base', base) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
129 ctxt.addGlobal('title', 'Just a test') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
130 ctxt.addGlobal('user', 'joe') |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
131 ctxt.addGlobal('items', ['Number %d' % num for num in range(1, 15)]) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
132 buf = StringIO() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
133 template.expand(ctxt, buf) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
134 return buf.getvalue() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
135 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
136 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
137 print render() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
138 return render |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
139 |
116 | 140 def run(engines, number=2000, verbose=False): |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
141 basepath = os.path.abspath(os.path.dirname(__file__)) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
142 for engine in engines: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
143 dirname = os.path.join(basepath, engine) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
144 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
145 print '%s:' % engine.capitalize() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
146 print '--------------------------------------------------------' |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
147 else: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
148 print '%s:' % engine.capitalize(), |
332
0e6ae0ade606
* Fixed `basic.py` benchmark on Windows, closing #72. Thanks to John M. Camara for reporting the issue and providing the fix.
cmlenz
parents:
319
diff
changeset
|
149 t = timeit.Timer(setup='from __main__ import %s; render = %s(r"%s", %s)' |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
150 % (engine, engine, dirname, verbose), |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
151 stmt='render()') |
116 | 152 time = t.timeit(number=number) / number |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
153 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
154 print '--------------------------------------------------------' |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
155 print '%.2f ms' % (1000 * time) |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
156 if verbose: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
157 print '--------------------------------------------------------' |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
158 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
159 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
160 if __name__ == '__main__': |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
161 engines = [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
|
162 if not engines: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
163 engines = __all__ |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
164 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
165 verbose = '-v' in sys.argv |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
166 |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
167 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
|
168 import hotshot, hotshot.stats |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
169 prof = hotshot.Profile("template.prof") |
116 | 170 benchtime = prof.runcall(run, engines, number=100, verbose=verbose) |
97
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
171 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
|
172 stats.strip_dirs() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
173 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
|
174 stats.print_stats() |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
175 else: |
33fee66e0e8a
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
176 run(engines, verbose=verbose) |