如何分析和获取Javascript性能 [英] How to profile and get Javascript performance

查看:142
本文介绍了如何分析和获取Javascript性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

配置javascript执行的最佳方式是什么?

我有一些使用jQuery的脚本,我想其中一个有内存泄漏。

I have a few scripts that use jQuery, and I think I have a memory leak in one of them.

如何分析和找到我使用最多内存/ CPU的脚本的哪些部分?

How one could profile and find what parts of the scripts that I have are using the most memory/CPU?

推荐答案

关于内存消耗>

JavaScript中的内存泄漏通常被忽略,除非它们变成浏览器内存泄漏(即,即使在用户离开页面后,内存仍继续分配并且没有办法释放它)。这样做的原因是,当您的Web应用程序可能有一些内存泄漏时,用户将从一个页面转到另一个页面,以便最大限度地减少泄漏。但是,他们可能无法重新启动浏览器,因此浏览器内存泄漏可能很严重。已知某些JavaScript代码会导致某些浏览器出现内存泄漏,因此Internet Explorer可能是此领域中最糟糕的。对于它,您可能会发现 Microsoft JavaScript内存泄漏检测器非常有用。

Memory leaks in JavaScript are usually ignored except when they turn into browser memory leaks (that is, even after the user navigates away from the page, the memory continues allocated and there's no way to free it). The reason for this is that while your web application may have some memory leaks, users will go from one page into another so the leaks are minimized. However they may not restart the browser, so browser memory leaks may be serious. Some JavaScript code is known to cause memory leaks on certain browsers, being Internet Explorer probably the worst in this area. For it you may find Microsoft JavaScript Memory Leak Detector to be very useful.

关于时间

IE,Chrome和Safari内置了分析器随浏览器一起提供的Web开发工具。对于Firefox,您可以使用Firebug。也很有用,因为你正在使用jQuery,这意味着你的分析报告将填充匿名函数等,使其非常难以理解, John Resig的jQuery profiling插件,它将为您提供更清晰的输出结果。

IE, Chrome and Safari have built in profilers in the web development tools that ship with the browser. For Firefox you may use Firebug. Also useful may be, since you're using jQuery which means your profiling report will be filled with anonymous functions and alike, making it quite unreadable, John Resig's jQuery profiling plugin, which will give you a clearer output on the matter.

这篇关于如何分析和获取Javascript性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆