This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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 ]
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
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
Joined: Nov 14, 2000
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.
Joined: Jun 03, 2002
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
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...
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)
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?
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.