annotate examples/bench/run.py @ 59:aa6ffd2d7274 trunk

Minor improvements to the benchmark thing.
author cmlenz
date Wed, 05 Jul 2006 07:58:36 +0000
parents 300b6a3b0730
children 448792ab1303
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
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
8 loader = TemplateLoader([dirname], False)
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
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
67 def main():
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
68 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
69 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
70 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
71 print '%s:' % engine.capitalize()
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
72 func = globals()[engine](dirname)
59
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
73 if not func:
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
74 print 'Skipping %s, not installed?' % engine.capitalize()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
75 continue
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
76 times = []
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
77 for i in range(100):
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
78 start = datetime.now()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
79 sys.stdout.write('.')
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
80 sys.stdout.flush()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
81 func()
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
82 times.append(datetime.now() - start)
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
83
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
84 print
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
85 total_ms = sum([t.seconds * 1000 + t.microseconds for t in times])
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
86 print ' --> timing: %s (avg), %s (min), %s (max)' % (
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
87 timedelta(microseconds=total_ms / len(times)),
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
88 timedelta(microseconds=min([t.seconds * 1000 + t.microseconds for t in times])),
aa6ffd2d7274 Minor improvements to the benchmark thing.
cmlenz
parents: 57
diff changeset
89 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
90 print
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
91
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
92 if __name__ == '__main__':
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
93 main()
Copyright (C) 2012-2017 Edgewall Software