Code runs much faster in debugger

7 views (last 30 days)
Rick
Rick on 18 Feb 2011
Hello,
I have a quite large project in Matlab, which involves object oriented programming. While running some tests I have noticed that parts of the code actually run significantly faster in debug mode. That is, I set a breakpoint at a line of code that whill never be executed, and boom the code executes 3 times faster.
The parts where the difference seems to occur are all in constructing a large, sparse matrix. E.g., a typical assignment for setting the values of a column:
obj.Hcoupling(coupledStates, k) = 0.5;
Hcoupling is a sparse matrix, coupledStates is a list of indices, k is a scalar. Can anybody tell me what is going on? How can this be possible? And, most importantly, how can I get this 3x speed increase in my normal program execution :-)
Thanks in advance,
Rick
PS. This "question form" with its fancy preview is HELL

Answers (2)

Andreas Goser
Andreas Goser on 18 Feb 2011
Not that I know WHY that is faster in debug mode, but one aspect is that The JIT accelerator is disabled when debugging. Naturally, the JIT accelerator shall accelerate, but it may be an issue in the JIT implementation. Please try:
feature('accel','off')
feature('jit','off')
And run your code. If it also runs faster, then there maybe is a JIT issue.

Rick
Rick on 18 Feb 2011
Thank you for the quick response.
Are those settings independent of each other? I treated them as such, and tested various configurations by setting them 'on' and 'off', but did not pay attention to in which order I set them.
The results I got thus far are that the 'jit' setting did not affect the speed of the particular section of code, but the 'accel' setting did. If 'accel' was set to off, the code was always slow (that means, in both normal and debug mode). If 'accel' was on, the code was fast in debug mode, but not in normal mode.
  1 Comment
Andreas Goser
Andreas Goser on 18 Feb 2011
So then the test appear to be not helpful. 'accel' 'on' should normally faster and that is what you observe. I was however suggesting that you compare the (both) 'off' settings with running in debug mode. But all in all it looks my attempt goes in the wrong way

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!