Mercurial > genshi > genshi-test
annotate examples/bench/run.py @ 57:b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
author | cmlenz |
---|---|
date | Tue, 04 Jul 2006 18:19:22 +0000 |
parents | |
children | 352d176b4f06 |
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 _measure_time(func, repeat=100): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
7 times = [] |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
8 for i in range(repeat): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
9 start = datetime.now() |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
10 sys.stdout.write('.') |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
11 sys.stdout.flush() |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
12 func() |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
13 times.append(datetime.now() - start) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
14 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
15 print |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
16 total_ms = sum([t.seconds * 1000 + t.microseconds for t in times]) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
17 print ' --> timing: %s (avg), %s (min), %s (max)' % ( |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
18 timedelta(microseconds=total_ms / len(times)), |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
19 timedelta(microseconds=min([t.seconds * 1000 + t.microseconds for t in times])), |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
20 timedelta(microseconds=max([t.seconds * 1000 + t.microseconds for t in times]))) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
21 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
22 def markup(dirname): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
23 from markup.template import Context, TemplateLoader |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
24 loader = TemplateLoader([dirname], False) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
25 template = loader.load('template.html') |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
26 def render(): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
27 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
|
28 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
|
29 template.generate(ctxt).render('html') |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
30 return render |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
31 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
32 def cheetah(dirname): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
33 # FIXME: infinite recursion somewhere... WTF? |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
34 from Cheetah.Template import Template |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
35 class MyTemplate(Template): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
36 def serverSidePath(self, path): return os.path.join(dirname, path) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
37 filename = os.path.join(dirname, 'template.tmpl') |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
38 template = MyTemplate(file=filename) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
39 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
40 def render(): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
41 template = MyTemplate(file=filename, |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
42 searchList=[{'title': 'Just a test', |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
43 'items': [u'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
|
44 template.respond() |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
45 return render |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
46 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
47 def clearsilver(dirname): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
48 import neo_cgi |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
49 neo_cgi.update() |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
50 import neo_util |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
51 import neo_cs |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
52 def render(): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
53 hdf = neo_util.HDF() |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
54 hdf.setValue('hdf.loadpaths.0', dirname) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
55 hdf.setValue('title', escape('Just a test')) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
56 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
|
57 hdf.setValue('items.%d' % (num - 1), escape('Number %d' % num)) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
58 cs = neo_cs.CS(hdf) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
59 cs.parseFile('template.cs') |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
60 return render |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
61 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
62 def kid(dirname): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
63 import kid |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
64 kid.path = kid.TemplatePath([dirname]) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
65 template = kid.Template(file='template.kid') |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
66 def render(): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
67 template = kid.Template(file='template.kid', |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
68 title='Just a test', |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
69 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
|
70 template.serialize(output='xhtml') |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
71 return render |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
72 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
73 def main(): |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 print '%s:' % engine.capitalize() |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
78 func = globals()[engine](dirname) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
79 _measure_time(func) |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
80 print |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
81 |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
82 if __name__ == '__main__': |
b387cf24d329
Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff
changeset
|
83 main() |