在不导致浏览器崩溃的情况下分析 JavaScript

发布于 2024-11-02 23:19:30 字数 383 浏览 0 评论 0原文

因此尝试分析一些代码,我发现最简单的方法(至少在 Firefox 上)是使用 consoletime/timeEndprofile/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 技术交流群。

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

发布评论

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

评论(5

唠甜嗑 2024-11-09 23:19:30

当我用来分析我的 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?

贩梦商人 2024-11-09 23:19:30

我尝试过在 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?

_蜘蛛 2024-11-09 23:19:30

虽然不是传统的代码分析器,但我推荐 Google 的 Speed Tracer

使用 Speed Tracer,您可以更好地了解应用程序中的时间花费情况。这包括 JavaScript 解析和执行、布局、CSS 样式重新计算和选择器匹配、DOM 事件处理、网络资源加载、计时器触发、XMLHttpRequest 回调、绘制等引起的问题。

Although not a traditional code profiler, I recommend Google's Speed Tracer:

Using Speed Tracer you are able to get a better picture of where time is being spent in your application. This includes problems caused by JavaScript parsing and execution, layout, CSS style recalculation and selector matching, DOM event handling, network resource loading, timer fires, XMLHttpRequest callbacks, painting, and more.

甩你一脸翔 2024-11-09 23:19:30

我认为 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.

阳光下慵懒的猫 2024-11-09 23:19:30

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

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