问题描述
背景
玉石语法很棒,但我想看看它是如何影响性能的。
jade syntax is awesome but i wanted to see how it was affecting performance.
所以我创建了一个单一的页面应用程序,并使用apache长凳来比较其使用玉的吞吐量来渲染页面,而不是使用内存字符串。没有变量,所以这是一个纯粹的学术比较。
So i created a single page app and used apache bench to compare its throughput using jade to render a page vs using an in memory string. There were no variables so this was a purely academic comparison.
内存字符串使整个应用程序在本地快了两倍多,这似乎很多考虑到玉石的生产模式应该从内存缓存中呈现。
The in memory string made the entire app more than twice as fast locally, which seems a lot considering jade in production mode should be rendering from an in memory cache.
我正在使用节点0.8,而在生产模式下使用快照的2.5.11版本,其视图缓存选项显式设置为 true
。
I'm using node 0.8 and the version 2.5.11 of express in production mode with the view cache option explicitly set to true
.
apache bench results:
apache bench results:https://dl.dropbox.com/u/3737990/jade/jade.pnghttps://dl.dropbox.com/u/3737990/jade/memory.png
推荐答案
如Harry所提到的,将模板引擎的性能与发送字符串的性能进行比较是无意义的,因为它们满足两个不同的需求。这有点像比较两辆车的MPG,除了一辆刚刚放入中立的汽车,让它滚下一座山。
As mentioned by Harry, it's meaningless to compare a template engine's performance to the performance of sending a string, since those address two different needs. It's somewhat like comparing the MPG of two cars, except one car you just put into neutral and let it roll down a hill.
相反,它更有帮助,一个href =http://jsperf.com/dom-vs-innerhtml-based-templating/511 =nofollow noreferrer>比较模板引擎,因为它们都是相同的目的(动态的渲染HTML)。
Instead, it is much more helpful to compare templating engines, since they are all means to the same ends (dynamically rendered HTML).
这里我们看到,Jade是最慢的模板语言。可能有很多因素可以解决为什么会这样的情况,但核心问题是Jade 。如果您需要非常高的性能,是为了速度而设计的。
Here we see that Jade is the slowest templating language. There are probably a lot of factors that play in to why this is the case, but the core issue is that Jade wasn't designed for speed. If you need extremely high performance, doT was designed for speed.
这篇关于可以采用哪些步骤来改善使用nodejs的快照中的玉模板渲染性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!