PHP 与 Node.js - 使用 Jade 的 Node.js 中的 HTML 渲染速度是否较慢?
假设我们每天有数百万个请求。使用 Jade 的 Node.js 中的 HTML 处理比 PHP 的渲染引擎慢还是快?或者没关系,因为差异真的很小?
我正在使用 Node.js 和 Jade模板引擎,我非常喜欢它。但我一直是那个担心表现的人。我的开发生涯是从 PHP 开始的,这很有趣,但现在 Node 似乎好多了,所以我决定切换。
我使用 Jade 来渲染 HTML,因为单独的 Node.js 缺少它(我知道这听起来有点愚蠢,因为 Jade 也是节点:P)。但因为 Jade 是 Node 中的一个模块,我有点困惑,也许这会减慢渲染过程。
Assuming that we have millions of requests per day. Is the HTML processing in Node.js with Jade slower or faster than PHP's render engine? Or doesn't matter because the difference is really small?
I'm using Node.js with the Jade template engine, I really like it. But I was always the guy who worried about performance. I started my developer career with PHP, it was fun but now Node seems much much better, so I decided to switch.
I use Jade to Render HTML, because node.js alone lacks it(I know this sounds a bit stupid because Jade is node too :P). But because Jade is a module in Node I'm a bit confused, maybe this can slow the rendering process down.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Jade 不是为速度而设计,而是为优雅而设计。如果您确实关心速度,还有其他更快的 JavaScript 渲染引擎。
查看 http://jsperf.com/dom-vs-innerhtml-based-templated /63 (请注意,chrome 结果与 Node.js 性能密切匹配)
但这都是假设渲染引擎是瓶颈,而不是数据库。
Jade isn't designed for speed, it's designed for elegance. If you're really concerned with speed there are other javascript rendering engines that are faster.
Check out http://jsperf.com/dom-vs-innerhtml-based-templating/63 (note that the chrome results match closely to node.js performance)
But that's all assuming the rendering engine is the bottleneck, and not the DB.
首先,我知道这是非常古老的,但我想对我的基准进行元标记,以帮助其他人寻求 Jade 与决策。由于我在选择模板引擎时遇到困难,因此我最近添加了一个比较两者的基准。我选择twig是因为我已经用过它并且从未使用过Jade。我确实喜欢 Jade 的简单性,并且对于构建“快速网络应用程序”很有帮助,但是我已经编写 HTML 和 CSS 超过 15 年了,看到这些标记让我微笑。
Express - Jade 与 Twig 基准:
First off, I know this is VERY OLD but I would like to meta tag my benchmark to help other seeking the Jade vs decisions. I added a benchmark comparing both recently since I got stuck picking out a template engine. I choose twig because I already used it and have never used Jade. I do like how simple Jade is and can be beneficial for getting "quick web apps" up however I've written HTML and CSS for over 15 years and seeing the markup makes me smile.
Express - Jade vs Twig Benchmarks:
Jade 模板是内存缓存的,因此第二个请求几乎是立即的。
如果您担心 jade 的模板速度,可以使用
self
选项。Jade templates are memory cached, so the second request will be almost immediate.
If you are concerned about templating speed with jade, you can use
self
option.Jade 中的视图被编译为实际的 Javascript,然后缓存以供以后使用。就渲染而言,Jade 与渲染用原始 Javascript 编写的页面一样快。编译时间确实会增加初始开销,但您应该只需要编译代码一次(最有可能在节点最初启动时)。
欢迎您运行测试,但基本上 php 通常会在每个请求上进行解释(显然 memache 确实会启动),而 jade 视图应该完成缓存在内存中。
The views in Jade are compiled to actual Javascript, and then cached for latter use. In terms of rendering Jade is as fast as rendering a page written in raw Javascript. The compile time does add an initial over head, but you should only need to compile the code once(most likely when node initially starts up).
Your welcome to run the tests, but basically php is typically interpreted on each request(obviously memache does kick in), while the jade views should be completed cached in memory.