How to find out which part of my code takes up more CPU

I would like to know which lines of my code use most of the runtime. I am running a scheduler algorithm, and it takes 5 minutes for a computer to find a solution to solve a specific problem that I made.

I use many recursion methods, I would like to know where the most time was wasted, so I can examine these lines and try to fix or reorganize the code to see if it helps.

I know that there are methods of cyclometric complexity. But I do not know how to use it on Eclipse. I am using Helios. Tried to set metrics2 and it just pops up errors on my Eclipse.

EDIT: SMALL NEW QUESTION:

http://s7.postimg.org/frd8yjql5/diag.png What does this mean? Look at the heap size. Always up and down .. does that affect processor speed? Thank!

+5
source share
3 answers

I would like to know which lines of my code use most of the runtime.

Run your code using the profiler. Eclipse supports profiling, but I would recommend using the profiler that comes as part of the JDK - VisualVM.

(I would not analyze the complexity of “big O.”. First, first, and this will tell you where to start. Then you may want to formally or informally look at the algorithmic complexity of the hot spots.)

I know that there are methods of cyclometric complexity.

. () , . , , "metrics2", .

+4

, .

O-. ( , Cyclomatic Complexity, ).

Cormen " " .

, , .

: , , .

( , ), , JVisualVM.

+2

, : http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Stopwatch.html

Basic usage:

Stopwatch stopwatch = new Stopwatch().start();
doSomething();
stopwatch.stop(); // optional

long millis = stopwatch.elapsed(MILLISECONDS);

log.info("that took: " + stopwatch); // formatted string like "12.3 ms"
+1

All Articles