Mercurial > genshi > mirror
annotate examples/bench/basic.py @ 171:7fcf8e04514e trunk
Follow-up to [214]: allow initializing `Attributes` with attribute names that contain dashes or conflict with a reserved word (such as ?class?.)
author | cmlenz |
---|---|
date | Fri, 18 Aug 2006 12:50:46 +0000 |
parents | 537f819c547b |
children | 84168828b074 |
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 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
7 __all__ = ['clearsilver', 'django', 'kid', 'markup', 'simpletal'] |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
8 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
9 def markup(dirname, verbose=False): |
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
|
10 from markup.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 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
22 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
|
23 # 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
|
24 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
|
25 class MyTemplate(Template): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
26 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
|
27 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
|
28 template = MyTemplate(file=filename) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
29 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
30 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
31 template = MyTemplate(file=filename, |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
32 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
|
33 '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
|
34 return template.respond() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
35 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
36 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
37 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
38 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
39 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
40 def clearsilver(dirname, verbose=False): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
41 import neo_cgi |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
42 neo_cgi.update() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
43 import neo_util |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
44 import neo_cs |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
45 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
46 hdf = neo_util.HDF() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 cs.parseFile('template.cs') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
54 return cs.render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
55 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
56 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
57 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
58 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
59 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
68 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
69 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
|
70 '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
|
71 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
|
72 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
73 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
74 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
75 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
76 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
77 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
|
78 import kid |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
79 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
|
80 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
|
81 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 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
|
86 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
87 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
88 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
89 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
90 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
91 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
|
92 # 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
|
93 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
|
94 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
|
95 def render(): |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
96 print template |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
97 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
98 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
99 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
100 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
101 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
102 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
|
103 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
|
104 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
|
105 base = simpleTAL.compileHTMLTemplate(fileobj) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
106 fileobj.close() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
107 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
|
108 template = simpleTAL.compileHTMLTemplate(fileobj) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
109 fileobj.close() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
110 def render(): |
103
0f246a30d3a7
benchmark: improved functionality of SimpleTAL example. Thanks to bruno desthuilliers for some tips.
cmlenz
parents:
97
diff
changeset
|
111 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
|
112 ctxt.addGlobal('base', base) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
113 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
|
114 ctxt.addGlobal('user', 'joe') |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
115 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
|
116 buf = StringIO() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
117 template.expand(ctxt, buf) |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
118 return buf.getvalue() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
119 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
120 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
121 print render() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
122 return render |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
123 |
116 | 124 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
|
125 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
|
126 for engine in engines: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
127 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
|
128 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
129 print '%s:' % engine.capitalize() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
130 print '--------------------------------------------------------' |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
131 else: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
132 print '%s:' % engine.capitalize(), |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
133 t = timeit.Timer(setup='from __main__ import %s; render = %s("%s", %s)' |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
134 % (engine, engine, dirname, verbose), |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
135 stmt='render()') |
116 | 136 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
|
137 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
138 print '--------------------------------------------------------' |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
139 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
|
140 if verbose: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
141 print '--------------------------------------------------------' |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
142 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
143 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
144 if __name__ == '__main__': |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
145 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
|
146 if not engines: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
147 engines = __all__ |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
148 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
149 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
|
150 |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
151 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
|
152 import hotshot, hotshot.stats |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
153 prof = hotshot.Profile("template.prof") |
116 | 154 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
|
155 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
|
156 stats.strip_dirs() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
157 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
|
158 stats.print_stats() |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
159 else: |
ff19219485cc
Add benchmark that builds a large HTML table using different templating techniques (provided by Jonas).
cmlenz
parents:
diff
changeset
|
160 run(engines, verbose=verbose) |