annotate examples/bench/run.py @ 61:448792ab1303 trunk

Use a different namespace than Kid uses.
author cmlenz
date Fri, 07 Jul 2006 17:54:52 +0000
parents aa6ffd2d7274
children c40a5dcd2b55
rev   line source
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
1 from cgi import escape
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
2 from datetime import datetime, timedelta
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
3 import os
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
4 import sys
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
5
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
6 def markup(dirname):
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
7 from markup.template import Context, TemplateLoader
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
8 loader = TemplateLoader([dirname])
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
9 template = loader.load('template.html')
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
10 def render():
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
11 ctxt = Context(title='Just a test',
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
12 items=['Number %d' % num for num in range(1, 15)])
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
13 template.generate(ctxt).render('html')
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
14 return render
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
15
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
16 def cheetah(dirname):
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
17 # FIXME: infinite recursion somewhere... WTF?
59
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
18 try:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
19 from Cheetah.Template import Template
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
20 class MyTemplate(Template):
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
21 def serverSidePath(self, path): return os.path.join(dirname, path)
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
22 filename = os.path.join(dirname, 'template.tmpl')
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
23 template = MyTemplate(file=filename)
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
24
59
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
25 def render():
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
26 template = MyTemplate(file=filename,
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
27 searchList=[{'title': 'Just a test',
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
28 'items': [u'Number %d' % num for num in range(1, 15)]}])
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
29 template.respond()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
30 return render
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
31 except ImportError:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
32 return None
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
33
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
34 def clearsilver(dirname):
59
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
35 try:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
36 import neo_cgi
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
37 neo_cgi.update()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
38 import neo_util
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
39 import neo_cs
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
40 def render():
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
41 hdf = neo_util.HDF()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
42 hdf.setValue('hdf.loadpaths.0', dirname)
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
43 hdf.setValue('title', escape('Just a test'))
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
44 for num in range(1, 15):
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
45 hdf.setValue('items.%d' % (num - 1), escape('Number %d' % num))
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
46 cs = neo_cs.CS(hdf)
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
47 cs.parseFile('template.cs')
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
48 cs.render()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
49 return render
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
50 except ImportError:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
51 return None
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
52
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
53 def kid(dirname):
59
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
54 try:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
55 import kid
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
56 kid.path = kid.TemplatePath([dirname])
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
57 template = kid.Template(file='template.kid')
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
58 def render():
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
59 template = kid.Template(file='template.kid',
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
60 title='Just a test',
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
61 items=['Number %d' % num for num in range(1, 15)])
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
62 template.serialize(output='xhtml')
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
63 return render
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
64 except ImportError:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
65 return None
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
66
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
67 def nevow(dirname):
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
68 # FIXME: can't figure out the API
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
69 try:
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
70 from nevow.loaders import xmlfile
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
71 template = xmlfile('template.xml', templateDir=dirname).load()
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
72 def render():
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
73 print template
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
74 return render
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
75 except ImportError:
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
76 return None
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
77
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
78 def main():
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
79 basepath = os.path.abspath(os.path.dirname(__file__))
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
80 for engine in ('markup', 'clearsilver', 'kid'):
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
81 dirname = os.path.join(basepath, engine)
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
82 print '%s:' % engine.capitalize()
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
83 func = globals()[engine](dirname)
59
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
84 if not func:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
85 print 'Skipping %s, not installed?' % engine.capitalize()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
86 continue
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
87 times = []
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
88 for i in range(100):
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
89 start = datetime.now()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
90 sys.stdout.write('.')
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
91 sys.stdout.flush()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
92 func()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
93 times.append(datetime.now() - start)
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
94
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
95 print
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
96 total_ms = sum([t.seconds * 1000 + t.microseconds for t in times])
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
97 print ' --> timing: %s (avg), %s (min), %s (max)' % (
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
98 timedelta(microseconds=total_ms / len(times)),
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
99 timedelta(microseconds=min([t.seconds * 1000 + t.microseconds for t in times])),
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
100 timedelta(microseconds=max([t.seconds * 1000 + t.microseconds for t in times])))
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
101 print
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
102
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
103 if __name__ == '__main__':
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
104 main()
Copyright (C) 2012-2017 Edgewall Software