Measuring Java execution time, memory usage and CPU load for a code segment

后端 未结 4 472
温柔的废话
温柔的废话 2020-12-04 19:36

For a particular segment of Java code, I\'d like to measure:

  • Execution time (most likely thread execution time)
4条回答
  •  执笔经年
    2020-12-04 20:38

    With the ThreadMXBean you can get CPU usage of individual threads and cpu time consumed rather than elapse time which may be useful.

    However, its often simpler to use a profiler as this process often generates a lot of data and you need a good visualisation tool to see what is going on.

    I use Yourkit as I find it easier to solve problems that other profilers I have used. I also use the builtin hprof as this can give you a different view on the profile of your application (but not as useful)

提交回复
热议问题