Tuning Java Performance? Think Japex

Unit testing has spawned a new type of development, test driven development. In TDD, test coverage leads the way in development, and it's a great way to develop new functionality.

Unfortunately performance tuning hasn't kept up with unit testing in terms of tools support and ubiquity. Usually when Java developers do performance tuning, it seems the strategy is generally ad-hoc and untargetted. I am certainly guilty of using this approach, and the code I've written suffers as a consequence. My ad-hoc approach is lame:
  • Write a main() method that exercises the code of interest
  • Sprinkle System.currentTimeMillis() calls throughout
  • Add extra code to warm-up HotSpot
  • Run the application, watching execution time getting printed to System.out
  • Cut and paste the execution time to a spreadsheet
  • Tweak the code of interest, randomly poking at things that look slow
  • Repeat the tests. If my change turns out to be slower, I check out the original implementation from CVS and redo the executions to confirm the data in the spreadsheet. Finally, I rollback the change.

    Japex GraphsBut there hasn't really been alternatives to this ad-hoc approach. Although tools like Netbeans Profiler and JProbe can analyze the performance of a single component, they're not good at comparing different implementations of the same component because they only work with one implementation at a time.

    Enter Japex. This fantastic tool is to performance testing what JUnit is to unit testing. Here's my new strategy, which is a much more efficient:
  • Create a Japex driver that exercises the code of interest
  • Refactor the API for the code of interest so I have one interface and N implementations. Each implementation uses a different strategy to accomplish the task
  • Edit a simple XML file to point to the driver and each of the implementations
  • Run Japex, a report with pretty bar charts is automatically saved (no spreadsheets!)
  • Tweak any implementation (or edit a copy) and re-execute Japex

    My code-compile-test cycle is now much faster. I'm able to try more things so I get a better understanding of the performance impact of each change. Just like how unit tests give me confidence to refactor, Japex gives me confidence to performance tune. Be sure to check it out, it's a worthy tool for your Java developer toolbox.