views:

59

answers:

2

Hi,

Is there a good way (proper way, or effective way) to debug slow running code?

I have a thread which runs multiple loops and then recurses and my code is running very slow.

Is there a good way to debug different loops or sections of code to find out which is running slowest?

If the debugger already does this, can someone please explain how,

Many thanks

A: 

One of the most primitive ways to determine slow points is to litter the code with print statements. Bottlenecks then show up as delays between prints. This can be improved by printing the system time as you move from one loop to another, making it trivial to determine the slowest loops.

A solution that is potentially easier and more thorough is to use a performance profiler. Most mainstream languages will have standalone profilers or debuggers with performance profiling built-in. A good profiler will determine the percentage of execution time spent on each area of your code and offer useful information for optimizing performance bottlenecks.

If you need more specific information it would be helpful to post the language you are using as well as relevant sections of the code.

Mandelbrot
+2  A: 

Hi,

What you need is not a debugger, but a profiler. Check this tool from Android's SDK: traceview

ognian
I think you can use the functionality of that tool within the Eclipse plugin too, although I haven't yet tried to do so.
MatrixFrog