衡量Java程序性能 [英] Measure Java Program Performance

查看:96
本文介绍了衡量Java程序性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧的应用程序,一个JAR文件,它进行了一些增强.基本上,必须修改部分代码,同时还要修改一些逻辑.

I had an old application, a JAR file, that went through some enhancements. Basically some parts of the code had to be modified along with modifying some of the logic.

将旧版本与新版本进行比较,新版本比旧版本慢大约2倍.

Comparing the OLD version against the NEW version, the NEW version is about 2X slower than the old one.

我正在尝试缩小导致减速的原因,但我发现自己使用System.currentTimeMillis()使用System.println来测量某些for循环的时间.这真的变得非常乏味.

I'm trying to narrow down whats causing the slow down, but I'm finding myself measuring the time for certain for-loops using System.println with System.currentTimeMillis(). This is really getting very tedious.

是否有Java性能工具可以帮助我弄清楚为什么NEW JAR比旧JAR慢2倍?

Is there a Java performance tool that will help me in figuring out why the NEW JAR is about 2X slower than the old one?

谢谢.

推荐答案

JProfiler 具有比较CPU快照的功能.记录新旧JAR文件的执行情况并保存快照(如果JVM最后退出,请配置"JVM退出"触发器以保存快照).

JProfiler has the capability to compare CPU snapshots. Record the execution for the old and the new JAR file and save snapshots (if the JVM exits at the end, configure a "JVM exit" trigger that saves a snapshot).

然后使用会话->在新窗口中比较快照"打开快照比较窗口,并添加两个快照.热点比较如下所示(在这种情况下,设置了视图过滤器):

Then open the snapshot comparison window with "Session->Compare Snapshots in New Window" and add the two snapshot. A hot spots comparison will look like this (a view filter is set in this case):

它将立即向您显示哪些方法导致执行时间增加.

It will immediately show you which methods are responsible for the increase in execution time.

分析执行时间差异的另一种方法是调用树比较,如下所示:

Another way to analyze the differences in execution time is the call tree comparison which will look like this:

免责声明:我的公司开发了JProfiler.

Disclaimer: My company develops JProfiler.

这篇关于衡量Java程序性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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