Code runs much faster in debugger

3 ビュー (過去 30 日間)
Rick
Rick 2011 年 2 月 18 日
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

回答 (2 件)

Andreas Goser
Andreas Goser 2011 年 2 月 18 日
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 2011 年 2 月 18 日
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 件のコメント
Andreas Goser
Andreas Goser 2011 年 2 月 18 日
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

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by