在不导致浏览器崩溃的情况下分析 JavaScript
因此尝试分析一些代码,我发现最简单的方法(至少在 Firefox 上)是使用 console
的 time
/timeEnd
或 profile
/profileEnd
,我都尝试了。
我遇到的问题是在 Firefox 崩溃之前我可以运行的次数。现在我不会将代码粘贴到这里,因为它是典型的基准测试代码(而且非常混乱),但显然它的要点是它运行函数(测试用函数表示),记录它们的执行时间一定数量运行次数。
现在以 5e4 为例,它可以工作,但我认为这不足以发现(非常)微观优化,但更重要的是,它会崩溃。
那么如何分析你的 JavaScript 呢?因为这种方式,几乎是不可能实现的。
So tried my hand at profiling some code and I figured the easiest way to do it (at least on Firefox) was to use either console
's time
/timeEnd
or profile
/profileEnd
, and I tried both.
The problem I have is with the number of runs I can do before Firefox crashes on me. Now I won't paste the code here because it's typical benchmarking code (and it's very messy), but obviously the gist of it is that it runs functions (a test is represented with a function), logging their execution time for a certain number of runs.
Now with for example, 5e4 it sorta works but I don't think it's enough to spot (very) micro optimizations, but more than that, it crashes.
So how do you profile your JavaScript? Because this way, it's barely feasible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我用来分析我的 JavaScript 代码时,我使用了 Chrome 的分析器;开发人员视图中的 JavaScript 控制台提供了它,它对我来说非常有用。你尝试过吗?
When I used to profile my JavaScript code I used Chrome's profiler; the JavaScript Console in the developer view gives it, and it pretty much worked for me. Have you ever tried it?
我尝试过在 FF4 上的 Firebug 中使用大量脚本来分析页面,在 Chrome(最新版本)中也进行同样的操作。 Firefox 一两秒内就崩溃了,Chrome 似乎没有问题。也许您可以在 Firebug 问题列表中找到相关内容?
I have tried profiling a page with a lot of scripting in Firebug on FF4 and the same in Chrome (last version). Firefox crashed within a second or two, Chrome didn't seem to have problems with it. Maybe you can find something on it in the Firebug issues list?
虽然不是传统的代码分析器,但我推荐 Google 的 Speed Tracer:
Although not a traditional code profiler, I recommend Google's Speed Tracer:
我认为 JavaScript 调试器(又名 Venkman)中的分析器相当不错。 addons.mozilla.org 上当前的版本与 Firefox 4 不兼容,但已进行了使其正常工作所需的更改。请参阅https://bugzilla.mozilla.org/show_bug.cgi?id=614557 了解详情。
I think the profiler in the JavaScript Debugger (aka Venkman) is quite good. The version currently on addons.mozilla.org is not compatible with Firefox 4, but the change necessary to make it work has been committed. See https://bugzilla.mozilla.org/show_bug.cgi?id=614557 for details.
dynaTrace AJAX 版(免费) - 您的包里又多了一个工具。恕我直言,提供了更详细的性能指标。他们以前只支持 IE,但他们的新版本也支持 FF。另请参阅 Steve Sounder 的博客
dynaTrace AJAX edition(free)- one more tool in your bag. Offers a little bit more detailed performance metrics, IMHO. They used to have it only for IE, but their new one supports FF too. Also see Steve Sounder's blog