aspose file tools*
The moose likes Java in General and the fly likes Best way to debug from Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Best way to debug from Java" Watch "Best way to debug from Java" New topic
Author

Best way to debug from Java

Rajan Kumar
Greenhorn

Joined: Jun 03, 2002
Posts: 11
Hi,
We usualy debug from our application using System.out.println() method.
But some applications might have dedicated class, Debugger which severs as entry point to debug from the code. Or they may have either log4j the famous logger framework for Java from apache Community, or someother third party framework.
Here my question is which type of the following implementation will give better performance if my caller calls the debugger something like this.

Implementation I

Which basically uses the getClass() method of the object and gets the name to print its name.
Implementation II

Which uses one HashMap to store the already found class names so that next time instead of calling using the objCaller.getClass().getName(), it picks from there.
My concern is whether I am approaching the problem in the right way, or over reacting for something which won't hit the performance.
Thanks in advance / Rajan Kumar
PS :
When I tested using for loop the HashMap based implementation is two times faster than the other one.
[ June 17, 2002: Message edited by: Rajan Kumar ]
[ June 17, 2002: Message edited by: Rajan Kumar ]
[ June 17, 2002: Message edited by: Rajan Kumar ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Rajan, with all due respect, you are overreacting to something about which you don't know wether it will hit performance in any meaningfull way. On the other hand, you *do* know that it will hit maintenance costs (as the "faster" solution is also the more complex one). You also have used time on thinking about this "problem" (of which you don't know wether it ever will become a problem) which you probably could have used better to implement something more in need by your customer. After all, it is very simple to later switch from solution 1 to solution 2 if you feel the actual need to, isn't it?
So, always remember the Three Rules Of Optimization:
1. Don't.
2. (for experts only) Don't - yet.
3. (if you *really* need to) Use a profiler to find the bottleneck - it isn't where you think it is.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Thank you Ilja!
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Here is another rule
http://ipdps.eece.unm.edu/1999/papers/053.pdf
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Aside from (or rather, because of) its simplicity, solution I has the added benefit of being faster, in the extremely unlikely event that you manage to create a situation where there is any discernable difference at all. But even if that weren't the case, ease of maintenance is most always more important than speed, as Ilja notes.
BTW Ilja - the your first two rules are of course frequently quoted elsewhere, originating from Michael A. Jackson in 1974 I believe. As for the third - is that one yours, or did it come from another source? Joshua Bloch said something similar in Effective Java, but I haven't seen that particular form elsewhere. Just curious...


"I'm not back." - Bill Harding, Twister
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
I've heard the third rule on the same form on Ilja's post at least once. Too lazy to find out where it came from.
Rajan Kumar
Greenhorn

Joined: Jun 03, 2002
Posts: 11
Hi Thanks for you suggestion.
Since I am working in a Product, I supposed to do these kind of finer level tunings, to acheive better performance.
-Regards / Rajan Kumar
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Roseanne Zhang:
Here is another rule
http://ipdps.eece.unm.edu/1999/papers/053.pdf

Huh, that's rather hard stuff, isn't it?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Jim Yingst:
BTW Ilja - the your first two rules are of course frequently quoted elsewhere, originating from Michael A. Jackson in 1974 I believe. As for the third - is that one yours, or did it come from another source? Joshua Bloch said something similar in Effective Java, but I haven't seen that particular form elsewhere. Just curious...

It's coming from http://c2.com/cgi/wiki?RulesOfOptimization - though that is probably not the original source...
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Rajan Kumar:
Since I am working in a Product, I supposed to do these kind of finer level tunings, to acheive better performance.

Rajan, that would be true if your resources were unconstraint, but most probably they aren't. So you have to think about how to get the most benefit from the resources you have.
In regard to improving performance you get almost invariably the most benefit by not guessing about the bottlenecks of your system but by finding them using a profiler. Even the most experienced experts are entering a slippery slope when they start "simply knowing" which part of a system will be a performance problem. The internet is full of such experience reports... (http://c2.com/cgi/wiki?OptimizationStories for example)
Honour Cook
Greenhorn

Joined: Nov 01, 2004
Posts: 9
Hi,

Just read this message and I have a question regarding to optimizing performance. Can anybody please tell me what the profile is? How can I use the profiler to find out the bottleneck of the performance?

Thanks a lot!
Honour
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by Honour Cook:
How can I use the profiler to find out the bottleneck of the performance?


Simply put, a traditional profiler runs a program and reports a list of methods called and the time they took to run. You look at the list, and see the slow methods. More sophisticated profilers show you "trees" of methods calling one another and track cumulative time.


[Jess in Action][AskingGoodQuestions]
Honour Cook
Greenhorn

Joined: Nov 01, 2004
Posts: 9
Thanks for your fast response.

Now I understand the profiler is an application. Is it a free tool for downloading? Could you please point me the direction where I can find a good profiler for JAVA application if you know any?

Very appreicate.

Honour
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best way to debug from Java