annotate examples/bench/run.py @ 76:85f70ec37112 trunk

Add Django to the benchmark.
author cmlenz
date Thu, 13 Jul 2006 09:17:21 +0000
parents 1da51d718391
children 8d6bee631a58
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 import os
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
3 import sys
69
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
4 import time
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
5 import timeit
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
6
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
7 __all__ = ['markup', 'clearsilver', 'django', 'kid']
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
8
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
9 def markup(dirname):
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
10 from markup.template import Context, TemplateLoader
69
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
11 loader = TemplateLoader([dirname], auto_reload=False)
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
12 template = loader.load('template.html')
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
13 def render():
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
14 ctxt = Context(title='Just a test', user='joe',
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
15 items=['Number %d' % num for num in range(1, 15)])
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
16 return template.generate(ctxt).render('html')
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
17 return render
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
18
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
19 def cheetah(dirname):
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
20 # FIXME: infinite recursion somewhere... WTF?
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
21 from Cheetah.Template import Template
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
22 class MyTemplate(Template):
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
23 def serverSidePath(self, path): return os.path.join(dirname, path)
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
24 filename = os.path.join(dirname, 'template.tmpl')
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
25 template = MyTemplate(file=filename)
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
26
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
27 def render():
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
28 template = MyTemplate(file=filename,
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
29 searchList=[{'title': 'Just a test', 'user': 'joe',
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
30 'items': [u'Number %d' % num for num in range(1, 15)]}])
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
31 return template.respond()
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
32 return render
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):
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
35 import neo_cgi
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
36 neo_cgi.update()
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
37 import neo_util
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
38 import neo_cs
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
39 def render():
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
40 hdf = neo_util.HDF()
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
41 hdf.setValue('hdf.loadpaths.0', dirname)
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
42 hdf.setValue('title', escape('Just a test'))
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
43 hdf.setValue('user', escape('joe'))
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
44 for num in range(1, 15):
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
45 hdf.setValue('items.%d' % (num - 1), escape('Number %d' % num))
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
46 cs = neo_cs.CS(hdf)
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
47 cs.parseFile('template.cs')
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
48 return cs.render()
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
49 return render
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
50
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
51 def django(dirname):
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
52 from django.conf import settings
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
53 settings.configure(TEMPLATE_DIRS=[os.path.join(dirname, 'templates')])
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
54 from django import template, templatetags
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
55 from django.template import loader
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
56 templatetags.__path__.append(os.path.join(dirname, 'templatetags'))
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
57 tmpl = loader.get_template('template.html')
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
58
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
59 def render():
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
60 data = {'title': 'Just a test', 'user': 'joe',
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
61 'items': ['Number %d' % num for num in range(1, 15)]}
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
62 return tmpl.render(template.Context(data))
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
63 return render
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
64
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
65 def kid(dirname):
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
66 import kid
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
67 kid.path = kid.TemplatePath([dirname])
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
68 template = kid.Template(file='template.kid')
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
69 def render():
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
70 template = kid.Template(file='template.kid',
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
71 title='Just a test', user='joe',
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
72 items=['Number %d' % num for num in range(1, 15)])
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
73 return template.serialize(output='xhtml')
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
74 return render
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
75
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
76 def nevow(dirname):
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
77 # FIXME: can't figure out the API
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
78 from nevow.loaders import xmlfile
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
79 template = xmlfile('template.xml', templateDir=dirname).load()
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
80 def render():
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
81 print template
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
82 return render
61
448792ab1303 Use a different namespace than Kid uses.
cmlenz
parents: 59
diff changeset
83
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
84 def run(engines):
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
85 basepath = os.path.abspath(os.path.dirname(__file__))
69
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
86 for engine in engines:
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
87 dirname = os.path.join(basepath, engine)
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
88 print '%s:' % engine.capitalize(),
69
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
89 t = timeit.Timer(setup='from __main__ import %s; render = %s("%s")'
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
90 % (engine, engine, dirname),
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
91 stmt='render()')
73
1da51d718391 Some more performance tweaks.
cmlenz
parents: 69
diff changeset
92 print '%.2f ms' % (1000 * t.timeit(number=2000) / 2000)
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
93
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
94
57
300b6a3b0730 Add some simple benchmarks to compare performance against Clearsilver, Kid, Cheetah, and more soon.
cmlenz
parents:
diff changeset
95 if __name__ == '__main__':
69
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
96 engines = [arg for arg in sys.argv[1:] if arg[0] != '-']
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
97 if not engines:
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
98 engines = __all__
69
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
99
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
100 if '-p' in sys.argv:
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
101 import hotshot, hotshot.stats
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
102 prof = hotshot.Profile("template.prof")
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
103 benchtime = prof.runcall(run, engines)
69
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
104 stats = hotshot.stats.load("template.prof")
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
105 stats.strip_dirs()
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
106 stats.sort_stats('time', 'calls')
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
107 stats.print_stats()
c40a5dcd2b55 A couple of minor performance improvements.
cmlenz
parents: 61
diff changeset
108 else:
76
85f70ec37112 Add Django to the benchmark.
cmlenz
parents: 73
diff changeset
109 run(engines)
Copyright (C) 2012-2017 Edgewall Software