• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to analyze the performance of java program

 
Ranch Hand
Posts: 205
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How do I analyze and conclude the performance of simple java program in general like have i used the right datatypes, do the program executes in less time, would i suppose to use any other datatypes for better performance etc. Also, how do I track the execution time of java program.

Please excuse if this is more of basic question.

Kindly let me know your suggestions.
 
JavaMonitor Support
Posts: 251
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Eshwar,

Use a profiler to see where your application spends its time. Then optimise those methods that are either called a lot, or that take a lot of time to execute.

Most performance is gained from a good design, though. But that is so application-specific that we cannot help you with that.
 
Ranch Hand
Posts: 86
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On this topic, what profiler tools do people recommend (for use inside Eclipse, specifically)?

I want to look at method timings, object instances, and total memory used by objects of any given class.

Thanks!
Toby
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
VisualVM and jhat (both free and installed tohether with the jvm) can give you the number of allocated instances.
For profiling method timings, I would not recommend visualvm or Netbeans or anything JVMTI/JVMPI/introspection based,because these profilers cause huge overheads and results are often bogus. My personal win is the StackProbe profiler - great accuracy, ease of use and low overheads, however it is free only for opensource projects.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Toby Eggitt wrote:On this topic, what profiler tools do people recommend (for use inside Eclipse, specifically)?
I want to look at method timings, object instances, and total memory used by objects of any given class.
Thanks!
Toby


The Eclipse Memory Analyzer Tool is a very nice for tool analyzing the heap inside Eclipse.

Othervise you could try JRockit Mission Control. It will also give you statistics about the number of object instances on the heap and how much memory they occupy, both live using the Memory Leak Detector or stored in a file for offline analysis using the JRA-tool. The overhead for method profiling is very low, less than 1% or so, because the tool piggybacks on the hot spot detector the JVM uses. You can get the the Eclipse plugins from the update site. The tool can also give you cheap memory allocation profiling.

Both tools are free to use for development and you can jump to the souce code in your Eclipse projects.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
YourKit profiler is my tool of choice - http://www.yourkit.com/
 
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this is a simplistic answer, but there are times when the easiest way to get the job done is to code a simple millisecond timer using Date methods, or maybe the Calendar interface. Place these at appropriate locations in your code, and you have a quick and easy way during development to measure improvements in algorithm speed, or check suspected bottlenecks, without having to mess around with learning a resource hungry performance evaluator.

p.s. I see this thread is a little old, but I thought I'd throw this in there.
 
Kees Jan Koster
JavaMonitor Support
Posts: 251
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Fred,

I agree and that is what I use mostly. Or rather, I mainly use a mish-mash of the tool-du-jour and print statements that do simple timing. Tools tend to find stuff you had never though of, and print statements serve to track problems that I know are there.
 
Lucas Lech
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fred Hamilton - I can't agree it's the best way to go, tweaking existing code to add the 'statistics gathering' by hand - I thought that's what the tools were for ? But hey, I might be wrong ;)
 
Fred Hamilton
Ranch Hand
Posts: 686
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lucas Lech wrote:Fred Hamilton - I can't agree it's the best way to go, tweaking existing code to add the 'statistics gathering' by hand - I thought that's what the tools were for ? But hey, I might be wrong ;)



Fair enough, but notice I said "sometimes" and I was speaking more of the development phase, looking for ways to refine algorithms to improve performance. And it depends how advanced of a programmer you are too. And I wasn't really talking about statistics gathering,unless you want to call putting a simple timer on a method call statistics gathering.

But yeah, once code is nailed down, their ain't much point in my suggestion. And if your performance analysis needs are complex, then I imagine my idea would fall short also.

regards.
 
Ranch Hand
Posts: 46
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to bring up this topic again.

I understand that it might be easier in my case to put in the print lines as I want to check the performance of my algorithms just like that.

Here's what I would like in short. I couldn't make much out from the above conversation.

How do I calculate the running time of my program.
How do I calculate the memory used by my program.

As of now I am using simple java programs. Might go in to bigger ones as I learn more. If possible, I would like a free software for the same as I am still not earning.

The craze got in me to find out the running times after participating in some online contests. They give some times with milli-second precision. If i could calculate, it would be great.

I saw the profiler in netbeans, but it always says 0 secs.

Max
 
Kees Jan Koster
JavaMonitor Support
Posts: 251
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Max,

Check these demo's: http://www.yourkit.com/docs/

Kees Jan
 
Maximus Moothiringus
Ranch Hand
Posts: 46
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to do the work. But seems like I can get only a 15day evaluation.

Will there be a free alternative to do this.

Or atleast some method with which I can find out just how much time my program takes to execute and how much memory it uses.

Max
 
Kees Jan Koster
JavaMonitor Support
Posts: 251
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Max,

There are some, like the netbeans profiler and project kato and the oktech profiler.
 
Maximus Moothiringus
Ranch Hand
Posts: 46
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, Will check.

Thank you very much.
Max
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
you can use jvmstat+visualgc together to see the garbage collection of your application so you can find if there is a memory leak in your application.
Eclipse MAT can only show you the analysis by reading a memory dump file. I have blogged about how to set up jvmstat+visualgc if you are interested here

Regards,
Dinuka
 
reply
    Bookmark Topic Watch Topic
  • New Topic