annotate examples/bench/run.py @ 61:33c2702cf6da

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