Mercurial > genshi > mirror
annotate examples/bench/basic.py @ 460:75425671b437 trunk
Apply patch by Alec Thomas for processing XML declarations (#111). Thanks!
author | cmlenz |
---|---|
date | Wed, 25 Apr 2007 19:41:09 +0000 |
parents | 97b0d21b81b7 |
children | bd00120ea90a |
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 from cgi import escape |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
2 import os |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
3 from StringIO import StringIO |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
4 import sys |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
5 import timeit |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
6 |
319
bab19496d4fa
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
ff19219485cc
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
ff19219485cc
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) |
ff19219485cc
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') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
13 def render(): |
149
537f819c547b
`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', |
537f819c547b
`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)]) |
537f819c547b
`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
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
17 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
18 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
19 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
20 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
21 |
319
bab19496d4fa
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): |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
23 from myghty import interp |
bab19496d4fa
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) |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
25 def render(): |
bab19496d4fa
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', |
bab19496d4fa
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)]) |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
28 buffer = StringIO() |
bab19496d4fa
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) |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
30 return buffer.getvalue() |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
31 if verbose: |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
32 print render() |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
33 return render |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
34 |
97
ff19219485cc
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): |
ff19219485cc
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? |
ff19219485cc
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 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
38 class MyTemplate(Template): |
ff19219485cc
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) |
ff19219485cc
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') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
41 template = MyTemplate(file=filename) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
42 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
43 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
44 template = MyTemplate(file=filename, |
ff19219485cc
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', |
ff19219485cc
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)]}]) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
47 return template.respond() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
48 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
49 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
50 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
51 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
52 |
ff19219485cc
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
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
54 try: |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
55 import neo_cgi |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
56 except ImportError: |
bab19496d4fa
Add [http://www.myghty.org/ Myghty] to the benchmarks, kindly contributed by Mike Bayer.
cmlenz
parents:
230
diff
changeset
|
57 return lambda:None |
97
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
58 neo_cgi.update() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
59 import neo_util |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
60 import neo_cs |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
61 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
62 hdf = neo_util.HDF() |
ff19219485cc
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) |
ff19219485cc
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')) |
ff19219485cc
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')) |
ff19219485cc
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): |
ff19219485cc
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)) |
ff19219485cc
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) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
69 cs.parseFile('template.cs') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
70 return cs.render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
71 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
72 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
73 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
74 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
75 |
ff19219485cc
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): |
ff19219485cc
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 |
ff19219485cc
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')]) |
ff19219485cc
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 |
ff19219485cc
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 |
ff19219485cc
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')) |
ff19219485cc
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') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
83 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
84 def render(): |
ff19219485cc
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', |
ff19219485cc
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)]} |
ff19219485cc
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)) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
88 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
89 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
90 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
91 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
92 |
ff19219485cc
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): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
94 import kid |
ff19219485cc
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]) |
ff19219485cc
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') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
97 def render(): |
ff19219485cc
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', |
ff19219485cc
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', |
ff19219485cc
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)]) |
ff19219485cc
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') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
102 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
103 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
104 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
105 return render |
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 def nevow(dirname, verbose=False): |
ff19219485cc
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 |
ff19219485cc
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 |
ff19219485cc
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() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
111 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
112 print template |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
113 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
114 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
115 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
116 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
117 |
ff19219485cc
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): |
ff19219485cc
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 |
ff19219485cc
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')) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
121 base = simpleTAL.compileHTMLTemplate(fileobj) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
122 fileobj.close() |
ff19219485cc
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')) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
124 template = simpleTAL.compileHTMLTemplate(fileobj) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
125 fileobj.close() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
126 def render(): |
103
0f246a30d3a7
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
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
128 ctxt.addGlobal('base', base) |
ff19219485cc
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') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
130 ctxt.addGlobal('user', 'joe') |
ff19219485cc
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)]) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
132 buf = StringIO() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
133 template.expand(ctxt, buf) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
134 return buf.getvalue() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
135 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
136 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
137 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
138 return render |
ff19219485cc
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
ff19219485cc
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__)) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
142 for engine in engines: |
ff19219485cc
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) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
144 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
145 print '%s:' % engine.capitalize() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
146 print '--------------------------------------------------------' |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
147 else: |
ff19219485cc
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
97b0d21b81b7
* 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
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
150 % (engine, engine, dirname, verbose), |
ff19219485cc
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
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
153 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
154 print '--------------------------------------------------------' |
ff19219485cc
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) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
156 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
157 print '--------------------------------------------------------' |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
158 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
159 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
160 if __name__ == '__main__': |
ff19219485cc
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] != '-'] |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
162 if not engines: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
163 engines = __all__ |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
164 |
ff19219485cc
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 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
166 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
167 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
|
168 import hotshot, hotshot.stats |
ff19219485cc
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
ff19219485cc
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") |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
172 stats.strip_dirs() |
ff19219485cc
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') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
174 stats.print_stats() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
175 else: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
176 run(engines, verbose=verbose) |