Why does adding a method level breakpoint have such a negative impact on program performance in debug mode?
Take the following (somewhat contrived) example:
public static void main(String[] args) {
long start = System.currentTimeMillis();
for(int a = 0; a <Integer.MAX_VALUE; a++) {
long v = a * a;
if(v == 100) {
doSomething();
}
}
System.out.println("Time: " + (System.currentTimeMillis() - start) + " ms");
}
private static void doSomething() { //*** BREAKPOINT 2
System.out.println("done something"); //*** BREAKPOINT 1
}
The performance of this is approximately:
- Not in debug: 4.5 seconds
- Debug, breakpoint 1: 6.0 seconds
- Debug, breakpoint 2: 47.0 seconds
What's going on? What benefit does the method level debug give us that normal ones can't?
Thanks!
EDIT
The timings are only approximations and include the time it takes me to react to the breakpoint and continue the application (which looks to be roughly about 1 second).
I appreciate that System.currentTimeMillis() is not 100% accurate, however the results are consistent over multiple tests and the difference in performance is massive! In fact, adding the method level breakpoint results in a warning from IntelliJ that it will have an impact on performance.