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

查看:32
本文介绍了如何分析和获取 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 Leak Detector 非常有用.

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 在浏览器附带的网络开发工具中内置了分析器.对于 Firefox,您可以使用 Firebug.也可能有用,因为您使用的是 jQuery,这意味着您的分析报告将填充匿名函数等,使其变得非常不可读,John Resig 的 jQuery 分析插件,它将为您提供更清晰的输出.

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天全站免登陆