V8 引擎将 JavaScript 编译为机器代码。那么,为什么 Node.js 不比 C 更快呢?

发布于 2024-10-03 09:52:15 字数 208 浏览 4 评论 0原文

根据语言基准测试,JavaScript V8 比其他编程语言更快在 regex-dna 程序中。那么,为什么node.js应用程序(即http服务器)不比C应用程序(即Nginx、Lighttpd)快呢?

According to language benchmarks, JavaScript V8 is faster than other programming languages at regex-dna program. So, why node.js applications (i.e. http server) isn't faster than C applications (i.e. Nginx, Lighttpd)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蓝眼睛不忧郁 2024-10-10 09:52:15

因为V8应用程序是javascript应用程序。即使 JavaScript 最终被编译为机器代码,运行时特性也是不同的。

例如,如果您调用对象中的函数,并且该对象未定义该函数,则运行时必须通过遍历原型层次结构来定位该函数,则该层次结构可以在程序的生命周期内随时更改。可以进行一些巧妙的优化,但开销仍然存在。

还有内存模型。 JavaScript 会被垃圾回收,GC 会占用 CPU 周期。

Because V8 applications are javascript applications. Even if the javascript is finally compiled to machine code the runtime characteristics are different.

For example if you call a function in an object and that object does not define the function the runtime must locate the function by traversing the prototype hierarchy, this hierarchy can change at any time during the lifetime of a program. There are clever optimizations that can be done but the overhead exists nevertheless.

There is also the memory model. Javascript is garbage collected and GC takes cpu cycles.

请远离我 2024-10-10 09:52:15

因为服务 http 请求是一个与 regex-dna 不同的问题。

A 在一项任务上比 B 快这一事实并不能说明对其他任务的期望。

强制性的坏车类比:火腿三明治比保时捷好吃得多。为什么从 0 到 60 不更快?

Because serving http requests is a different problem than regex-dna.

The fact that A is faster than B at one task doesn't say anything about what to expect from some other task.

Obligatory bad car analogy: A ham sandwich is much tastier than a porsche. Why isn't it faster from 0-60?

檐上三寸雪 2024-10-10 09:52:15

对于 C 来说,它本质上是计算速度的基准语言。现在的编译器非常好,可以生成非常高效的机器代码。这意味着性能的上限是使用 C 所能获得的。

在他关于 Node.js 的一场演讲中,Ryan Dahl(创建者)节点的速度和C差不多。(但是GC和其他东西确实对性能有影响,更不用说V8需要时间来正确优化东西)

For one C is essentially the benchmark language for computation speed. The compliers these days are very good and produce very efficient machine code. What this means is that the upper limit for performance is what you can get with C.

In one of his presentations about node.js Ryan Dahl (the creator) said that node is about as fast as C. (but GC and other things do have an impact on performance, not to mention that V8 needs time to properly optimize things)

等待我真够勒 2024-10-10 09:52:15

在该基准测试中,有 15 个不同的程序,只有一个 dna-regex 基准测试可以看到 JavaScript V8 更快。在其他基准测试中,JavaScript 的性能要低得多。您可以在第一个选择中选择程序,查看

In the that benchmark there are 15 different programs and only one dna-regex benchmark where you can see JavaScript V8 is faster. On other benchmarks JavaScript is much lower in performance. You can choose program in the first select, look at this one.

终止放荡 2024-10-10 09:52:15

根据语言基准, JavaScript V8 在二叉树程序中比 GCC 快。

根据语言基准测试,JavaScript V8 在 k 核苷酸程序上比 GCC 快。

根据语言基准测试,JavaScript V8 在 n 体程序中比 GCC 快。

根据语言基准测试,JavaScript V8 在频谱范数程序上比 GCC 快。

根据语言基准测试,JavaScript V8 在 fasta 程序中比 GCC 快。

根据语言基准测试,JavaScript V8 在反向补码程序上比 GCC 快。

根据语言基准测试,JavaScript V8 在 pidigits 程序中比 GCC 快。

According to language benchmarks, JavaScript V8 is not faster than GCC at binary-trees program.

According to language benchmarks, JavaScript V8 is not faster than GCC at k-nucleotide program.

According to language benchmarks, JavaScript V8 is not faster than GCC at n-body program.

According to language benchmarks, JavaScript V8 is not faster than GCC at spectral-norm program.

According to language benchmarks, JavaScript V8 is not faster than GCC at fasta program.

According to language benchmarks, JavaScript V8 is not faster than GCC at reverse-complement program.

According to language benchmarks, JavaScript V8 is not faster than GCC at pidigits program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文