cmlenz@3: #!/usr/bin/python cmlenz@3: # -*- coding: utf-8 -*- cmlenz@3: cmlenz@3: from datetime import datetime, timedelta cmlenz@3: import os cmlenz@3: import sys cmlenz@3: cmlenz@3: from markup.template import Context, TemplateLoader cmlenz@3: cmlenz@3: def test(): cmlenz@3: base_path = os.path.dirname(os.path.abspath(__file__)) cmlenz@3: loader = TemplateLoader([os.path.join(base_path, 'common'), cmlenz@3: os.path.join(base_path, 'module')], cmlenz@3: auto_reload=True) cmlenz@3: cmlenz@3: start = datetime.now() cmlenz@3: tmpl = loader.load('test.html') cmlenz@3: print ' --> parse stage: ', datetime.now() - start cmlenz@3: cmlenz@3: ctxt = Context(hello='', skin='default', hey='ZYX', bozz=None, cmlenz@3: items=['Number %d' % num for num in range(1, 15)], cmlenz@3: prefix='#') cmlenz@3: cmlenz@3: print tmpl.generate(ctxt).render(method='html') cmlenz@3: cmlenz@3: times = [] cmlenz@3: for i in range(100): cmlenz@3: start = datetime.now() cmlenz@3: list(tmpl.generate(ctxt)) cmlenz@3: sys.stdout.write('.') cmlenz@3: sys.stdout.flush() cmlenz@3: times.append(datetime.now() - start) cmlenz@3: print cmlenz@3: cmlenz@3: total_ms = sum([t.seconds * 1000 + t.microseconds for t in times]) cmlenz@3: print ' --> render stage: %s (avg), %s (min), %s (max)' % ( cmlenz@3: timedelta(microseconds=total_ms / len(times)), cmlenz@3: timedelta(microseconds=min([t.seconds * 1000 + t.microseconds for t in times])), cmlenz@3: timedelta(microseconds=max([t.seconds * 1000 + t.microseconds for t in times]))) cmlenz@3: cmlenz@3: if __name__ == '__main__': cmlenz@3: if '-p' in sys.argv: cmlenz@3: import hotshot, hotshot.stats cmlenz@3: prof = hotshot.Profile("template.prof") cmlenz@3: benchtime = prof.runcall(test) cmlenz@3: stats = hotshot.stats.load("template.prof") cmlenz@3: stats.strip_dirs() cmlenz@3: stats.sort_stats('time', 'calls') cmlenz@3: stats.print_stats() cmlenz@3: else: cmlenz@3: test()