分析是什么以及如何分析我的 Java 程序?
我听说过很多关于剖析的事情。 这是怎么回事? 据我了解,这是某种绩效衡量,但有人可以更清楚地阐述这一点,以便新手能够掌握这个想法。 另外,我将 Eclipse IDE 用于我的 Java 程序。 我可以使用 Eclipse IDE 分析我的程序吗? 分析时要考虑哪些因素(我的意思是最佳实践)?
I've heard a lot about profiling. What is this all about? As far as I understand this is some kind of performance measurement but can someone elaborate this on more clearly so that a newbie can grasp the idea. Also, I use Eclipse IDE for my Java program. Can I profile my program using Eclipse IDE? What are the factors to be considered while profiling (I mean the best practices)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
分析基本上显示给定代码行的执行频率以及在其中花费的时间(与其他行相比)。 这使得您可以轻松地查明代码大部分时间花费的位置。
它还可以找到代码花费大量时间而不执行任何操作的地方:这是 缓存未命中,这是您应该活跃起来的地方。
通常,程序会在一个地方花费大量时间(例如 90%)。 不幸的是,不进行分析就不可能找到这个地方。 猜测常常会出错。 因此,如果您在错误的地方进行优化,这根本没有帮助:如果该行花费的总时间只有 10%,那么您的代码只会快 10%(最多!)。 然而,如果您成功地删除了花费 90% 时间的调用,您的程序将变得十倍。
简而言之,这就是分析。
Eclipse 提供了内置的分析功能,有人告诉我它们非常好,但由于我不了解它们,所以让其他人来回答吧。
Profiling basically shows you how often a given line of code is executed and how much time was spent in it (compared to other lines). This makes it easy to pinpoint the location where your code spends most of the time.
It also makes it possible to find places where your code spends much time without doing anything: this is the typical sign of a cache miss and this is where you should get active.
Usually, programs spend very much time (say, 90%) in one place. Unfortunately, finding this place without profiling isn't possible. Guesswork often goes awry. So if you optimize in the wrong place, this won't help at all: if the overall time spent in that line is only 10%, your code will only get 10% faster (at best!). If, however, you succeed in removing the call that takes 90% of the time, your programm will get ten times faster.
This, in a nutshell, is profiling.
Eclipse offers builtin profiling capabilies and I've been told that they're pretty good but since I don't know them, let someone else answer that.
Konrad 是对的,但分析还涵盖程序的其他方面,例如内存消耗。
Konrad is right, but profiling covers other aspects of your program as well, such as memory consumption.
根据我对使用 Eclipse 进行 Java 分析所做的少量研究,您可以使用 JProfiler。 不过,除了安装它并快速观察之外,我从来没有真正做过更多的事情。
From what little research I've done on Java profiling with Eclipse, you can use JProfiler. I never really got much further than installing it and having a quick nose around though.
YourKit 是一个优秀的 Java 分析器,并且可以与 Eclipse 很好地集成。 它绝对物有所值,并且通常被认为是可用的最好的 Java 分析器。
YourKit is an excellent profiler for Java and will integrate nicely with Eclipse. It is definitely worth the money and generally thought to be the best Java profiler available.