Mercurial > genshi > genshi-test
annotate examples/basic/kidrun.py @ 912:46db99909472 experimental-py3k
py3k branch: add 2to3 build infrastructure to setup.py (this pulls the tests into the source distribution so that tests can be run after building with 2to3)
author | hodgestar |
---|---|
date | Sun, 24 Oct 2010 21:09:36 +0000 |
parents | c82c002d4c32 |
children |
rev | line source |
---|---|
73 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
3 | 4 import os |
5 import sys | |
73 | 6 import time |
3 | 7 |
8 import kid | |
9 | |
10 def test(): | |
11 base_path = os.path.dirname(os.path.abspath(__file__)) | |
21
eca77129518a
* Include paths are now interpreted relative to the path of the including template. Closes #3.
cmlenz
parents:
3
diff
changeset
|
12 kid.path = kid.TemplatePath([base_path]) |
3 | 13 |
14 ctxt = dict(hello='<world>', hey='ZYX', bozz=None, | |
15 items=['Number %d' % num for num in range(1, 15)], | |
16 prefix='#') | |
17 | |
73 | 18 start = time.clock() |
3 | 19 template = kid.Template(file='test.kid', **ctxt) |
73 | 20 print ' --> parse stage: %.4f ms' % ((time.clock() - start) * 1000) |
21 | |
22 for output in template.generate(): | |
23 sys.stdout.write(output) | |
24 print | |
3 | 25 |
26 times = [] | |
73 | 27 for i in range(1000): |
28 start = time.clock() | |
29 list(template.generate()) | |
30 times.append(time.clock() - start) | |
31 sys.stdout.write('.') | |
32 sys.stdout.flush() | |
3 | 33 print |
34 | |
73 | 35 print ' --> render stage: %s ms (average)' % ( |
36 (sum(times) / len(times) * 1000)) | |
3 | 37 |
38 if __name__ == '__main__': | |
39 if '-p' in sys.argv: | |
82 | 40 import hotshot, hotshot.stats |
41 prof = hotshot.Profile("template.prof") | |
42 benchtime = prof.runcall(test) | |
43 stats = hotshot.stats.load("template.prof") | |
44 stats.strip_dirs() | |
45 stats.sort_stats('time', 'calls') | |
46 stats.print_stats() | |
3 | 47 else: |
48 test() |