You want to track down potential performance and scalability problems but are unsure of the tools you need.
Use a commercial profiling tool, such as JProbe or OptimizeIt, to manually inspect code and identify application bottlenecks. Use JUnitPerf to ensure that new features and refactoring do not slow down code that used to be fast enough.
JUnitPerf is a tool for continuous performance testing. The goal of a performance test is to ensure that the code executes fast enough, even under varying load conditions. Let's take a look at a typical scenario.
You just completed a custom search algorithm, complete with a suite of JUnit tests. Next, the code is run through a profiling tool to look for any potential bottlenecks. If any performance issues are found, a new JUnit test is written to isolate the code (if one does not already exist). For example, the profiling tool reports that the search took ten seconds, but requirements dictate that it execute in less than three. The new JUnit test is wrapped around a JUnitPerf TimedTest to expose the performance bug. The timed test should fail; otherwise, there is no performance issue with the code you have isolated. Next, refactor the code that is causing the performance problem until the timed test passes.
|
Here are the typical steps for writing a JUnitPerf test:
Write a JUnit test suite for you search algorithm.
Run the search algorithm through a profiling tool to find bottlenecks.
|
If performance is an issue, write another JUnit test to isolate the code with poor performance (if one does not already exist).
Write a JUnitPerf TimedTest for the new JUnit test. The test should fail. If the test passes, there is no performance issue with the code you have isolated.
Tune the code until the performance test passes.
Recipe 8.3 shows how to create a JUnitPerf TimedTest. Recipe 8.7 shows how to use Ant to execute JUnitPerf tests.