Skip to content

Commit

Permalink
Add option to print out generated template code in benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed Jul 28, 2011
1 parent fa5b0f2 commit 8c3e46c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions demos/benchmark/template_benchmark.py
Expand Up @@ -3,12 +3,14 @@
# A simple benchmark of tornado template rendering, based on
# https://github.com/mitsuhiko/jinja2/blob/master/examples/bench.py

import sys
from timeit import Timer

from tornado.options import options, define, parse_command_line
from tornado.template import Template

define('num', default=100, help='number of iterations')
define('dump', default=False, help='print template generated code and exit')

context = {
'page_title': 'mitsuhiko\'s benchmark',
Expand Down Expand Up @@ -54,6 +56,9 @@ def render():

def main():
parse_command_line()
if options.dump:
print tmpl.code
sys.exit(0)
t = Timer(render)
results = t.timeit(options.num) / options.num
print '%0.3f ms per iteration' % (results*1000)
Expand Down

0 comments on commit 8c3e46c

Please sign in to comment.