|
Last change
on this file was
299,
checked in by cmlenz, 17 years ago
|
|
Fixed EOL style.
|
-
Property svn:eol-style set to
native
-
Property svn:executable set to
*
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | #!/usr/bin/python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | |
|---|
| 4 | import os |
|---|
| 5 | import sys |
|---|
| 6 | import time |
|---|
| 7 | |
|---|
| 8 | import kid |
|---|
| 9 | |
|---|
| 10 | def test(): |
|---|
| 11 | base_path = os.path.dirname(os.path.abspath(__file__)) |
|---|
| 12 | kid.path = kid.TemplatePath([base_path]) |
|---|
| 13 | |
|---|
| 14 | ctxt = dict(hello='<world>', hey='ZYX', bozz=None, |
|---|
| 15 | items=['Number %d' % num for num in range(1, 15)], |
|---|
| 16 | prefix='#') |
|---|
| 17 | |
|---|
| 18 | start = time.clock() |
|---|
| 19 | template = kid.Template(file='test.kid', **ctxt) |
|---|
| 20 | print ' --> parse stage: %.4f ms' % ((time.clock() - start) * 1000) |
|---|
| 21 | |
|---|
| 22 | for output in template.generate(): |
|---|
| 23 | sys.stdout.write(output) |
|---|
| 24 | print |
|---|
| 25 | |
|---|
| 26 | times = [] |
|---|
| 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() |
|---|
| 33 | print |
|---|
| 34 | |
|---|
| 35 | print ' --> render stage: %s ms (average)' % ( |
|---|
| 36 | (sum(times) / len(times) * 1000)) |
|---|
| 37 | |
|---|
| 38 | if __name__ == '__main__': |
|---|
| 39 | if '-p' in sys.argv: |
|---|
| 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() |
|---|
| 47 | else: |
|---|
| 48 | test() |
|---|
Note: See
TracBrowser
for help on using the repository browser.