Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best way to debug from Java

 
Rajan Kumar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Ilja!
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is another rule
http://ipdps.eece.unm.edu/1999/papers/053.pdf
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Honour Cook
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic