5

I was asked to profile (using some tool, such as YourKit or JVisualVM) a couple of implementations of the Traveling Salesman Problem (find the minimum path that visits all the given set of cities), in the context of a Algorithms Analysis and Design graduate course.

Taking in consideration the brute force approach of the algorithm, I'm wondering, though, how to best use the tools (for instance, JVisualVM) to analyze the spatial and temporal complexities of the algorithm. If I'm not in error the algorithm has spatial complexity of O(n), as it basically grows linearly with the number of cities, while it is O(n!) in temporal complexity.

The math isn't the issue here.

After playing for a bit with both the referred tools, I'm having some hard time understanding how can they be of any use to my problem.

Sure I can see which methods are being used the most and which % of the time is being used in each one of them, and what is the actual memory footprint, so that can be all be regarded as hints where to optimize.

But other than that, and other than seeing the % of the CPU which is actually being used (or IO accesses, which never occur in this program), I can't see how can I actually learn something about the algorithm with these tools than the math before referred didn't.

What should be my main concerns when using profilers to the analysis of algorithms? Also, I've put basic time recording capabilities embedded in my program. Maybe I could use the profiling tools to better do that job?

Thanks

1 Answers1

2

I typically use the Performance Diagnostic Model (PDM) approach as taught by Kirk Pepperdine (he's a world leading expert on Java performance). One of the things it teaches is that the profiler is a scalpel you use once you've diagnosed the general nature of the performance problem / analysis you want to do. You typically start with looking at who the dominant consumer of the CPU is. This can be:

  1. System (i.e. Operating System/Hardware)
  2. User (which in turn splits into JVM or the Application)
  3. No dominator (which generally means CPU starvation)

So my question is - What question are you trying to answer in analysing these implementations? Is it their performance? If so then the profiler is actually the wrong place to start (starting with the profiler is common misconception that's taught).