title: Flask + Jinja2: how to measure performances
body: <p>I need to compare the performances of a Flask application that uses <code>jinja2.Template.render</code> against <code>jinja2.Template.stream</code> to be sure that there is no loss of performances using the streaming of templates.</p>
  
  <p>My (very simple) idea was to print the timestamp before and after the rendering of the template, but since the webpage is returned by a function, I'm not quite sure how to implement this...</p>
  
  <p>My function is:</p>
  
  <pre><code>def index():
      """main function"""
      env = Environment(loader=FileSystemLoader(basedir+'templates'))
      #I modify the global variables
      env.globals['foo'] = 'bar'
      env.globals['build_response']=build_response
      get_url = request.args.get('to_print', None)
      message = "the input was \"%s\"" % (get_url,)
      template = env.get_template('body.html')
      return Response(template.stream(message=message))
      #return template.render(message=message)
  </code></pre>
  
  <p>And what I need to measure is the time spent by </p>
  
  <pre><code>return template.render(message=message)
  </code></pre>
  
  <p>vs</p>
  
  <pre><code>return Response(template.stream(message=message))
  </code></pre>
  
  <p>thanks!</p>