Can a profiler change the execution time of recursive calls to run in Java?

I am working on refactoring some Java code, so I'm going to adjust the time so that the code does not become slower. However, the new reorganized code seems to take longer than the source code. It is noteworthy that when I run the code with the profiler, the new code is much faster than the old code. The main difference is that the old code is recursive and the new iterative. Can the profiler affect the recursive code for several hundred thousand, and affecting iterative code only 1.5 times?

I work on Mac OS X 10.6.6, 3 GB of RAM, at 2.4 GHz, using the default Netbeans 6.9 profiler with a 64-bit Java 1.6.0__22 server.

(Both methods have self-synchronization code using System.currentTimeMillis () to allow me to compare times when the profiler is not used, but this should not noticeably affect things.)

+3
source share
3 answers

Yes. Most profiles use toolkits at the level of method calls. In a recursive form, the profiler must perform much more measurements than in an iterative form. While profilers are trying to extract overhead from them, it is very difficult to make reliable. Different profilers will be better / worse.

+7
source

Java, , . , , , .

. .

, / , , .

, . , . / , , .


( System.currentTimeMillis(), , , .)

:

  • currentTimeMillis() 1 , .

  • , , , JIT GC. .

+1

, , , . . , , , , , .

, , . - -- ( ), , - . , , ; , , , . , - 10% 10 , , .

, , .

.

+1

Source: https://habr.com/ru/post/1788606/


All Articles