Using a Profiler to Optimizer your Code

By Kevin Conroy
Back to the Main Page
Last updated August 25, 2004


The most important thSeptember 15, 2004 it to behave correctly. Once you have the behavior down, then you can worry about getting it to go faster. In order to help you find bottlenecks in your code quickly, consider using a Profiler.

A profiler is a utility that you run your program on top of/with. Profilers typically watch all of your function calls and time how long you spend executing each function and how many times it is called. A good profiler will show you a report of this information and allow you sort it and filter it by classes/packages. Thus, the Profiler will tell you which functions you're spending the most time in. Some profilers may even tell you how much time you're spending in the Java API (or whatever framework you're using), helping you to see when you're making overly-expensive calls to Java functions that you may be able to avoid.

Using a profiler isn't required, of course. But for those of you who finish early and want to do well when Brian (or the current TA) races your code, using a profiler will help you quickly find the parts of your code that need the most optimization.

Go to google.com and sourceforge.net to search for a profiler that works for you. There are many that can plug into your IDE so try searching for one that integrates into your IDE first. (And as always, be careful when downloading stuff from the internet. If you make your IDE unstable you want to make sure that it happens AFTER you've completed the project and have submitted a working copy. Nothing is worse than having IDE/system trouble that prevents you from getting good coding done.) That's not to say that any profiler will make your system unstable - hardly. Just saying that use some basic fault tolerance tricks to protect yourself from potential problems from using programs that other people have written in a non-fault tolerant manner. But that's just general common sense stuff to everyone, right? ;-)


By Kevin Conroy
Back to the Main Page
Last updated August 25, 2004

September 15, 2004