JS中函数声明速度差异
我运行了一个简单的 jsperf 测试,在 Firefox 中运行时一切都按预期进行,但当我在 Google Chrome 中运行测试时却感到困惑。
该测试正在测试在 JavaScript 中声明函数然后调用它们的不同方式。我的猜测是 Chrome 正在对 JavaScript 函数进行某种优化,但我不确定是什么或为什么会有如此大的差异。非常感谢任何帮助或链接来更好地理解这一点。
测试链接=> http://jsperf.com/function -assignment-semicolon/2
在 Firefox 中测试运行:
在 Chrome 中测试:
编辑:
我期望从 Firefox 获得结果,因为我期望它们是 - 每次测试都相当相同 - 比在 Google Chrome 中运行时慢
I ran a simple jsperf test and everything went as expected when running in Firefox but when I ran the test in Google Chrome is was confused.
The test is testing different ways of declaring function in JavaScript and then calling them. My guess is that Chrome is doing some sort of optimization on the JavaScript function but I'm not sure what or why there is such a big difference. Any help or links to understand this better is greatly appreciated.
Link to test => http://jsperf.com/function-assignment-semicolon/2
Test run in Firefox:
Test in Chrome:
Edit:
I expected the results I got from Firefox because I expected them to be
- fairly the same for each test
- slower than when run in Google Chrome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
死代码,完美的优化器会删除测试中的所有内容。随着最近发布的谷歌曲轴引擎,各个新闻网站都提到了这一点。风格之间的差异表明了实现死代码优化是多么困难。
http://tech .slashdot.org/story/10/12/07/2027259/Google-Quietly-Posts-Big-JavaScript-Engine-Update
Dead code, a perfect optimizer would remove everything in the test. This has been mentioned on various news sites with the recent announcement of Google's Crankshaft engine. The differences between styles are an indication of how difficult it is to implement dead code optimisation.
http://tech.slashdot.org/story/10/12/07/2027259/Google-Quietly-Posts-Big-JavaScript-Engine-Update