烧瓶 + Jinja2:如何衡量性能
我需要将使用 jinja2.Template.render
的 Flask 应用程序的性能与 jinja2.Template.stream
进行比较,以确保使用流式处理不会造成性能损失模板。
我的(非常简单)的想法是打印模板渲染之前和之后的时间戳,但是由于网页是由函数返回的,我不太确定如何实现这个......
是:
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)
我的功能 所花费的时间,
return template.render(message=message)
需要测量的是vs
return Response(template.stream(message=message))
谢谢!
I need to compare the performances of a Flask application that uses jinja2.Template.render
against jinja2.Template.stream
to be sure that there is no loss of performances using the streaming of templates.
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...
My function is:
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)
And what I need to measure is the time spent by
return template.render(message=message)
vs
return Response(template.stream(message=message))
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在通话之前和之后查看系统时钟。
如果您不立即从 template.render 或 template.stream 返回响应,则执行此操作会更容易。
IE:
You need to look at the system clock before and after the call.
It's easier to do this if you don't immediately return the response from template.render or template.stream.
IE: