Order of magnitude (10 times greater) execution time resulting from order of computations in a script file that are otherwise identical.

I have two script files attached that are computationally identical except for the positioning of one equation in a nested set of for-loops. "DynamWave_Ponding_2D_V_Chan_Mod1.m" has the single equation at line 91 (commented as "fast position"). "DynamWave_Ponding_2D_V_Chan_Mod2.m" has the same equation moved to line 165 (commented as "slow position"). There is no difference logically or computationally in either position (that I can determine), but the ..Mod1.m executes 10 times faster than the ..Mod2.m . I would like to learn why it makes such a major difference in the execution times. Thanks.

5 commentaires

I removed the semi-column after the toc to see the time, and on my old laptop with R2015b, they take both the same time of ~31s.
They take equal time on my Mac using R015b.
I am running R2015A, and I have repeated the comparison experiment many times over the past week or so, with identical results (10 fold increase) from about 8 sec to 80 sec on my Dell Optiplex 980 (Windows 7 64 bit) with 16 Gb memory (always repeatable with less than 0.2 sec variation). I wonder if a bug in my MATLAB interpreter is at the root of this problem. I may try to get R2015B installed to see if that makes a difference.
I ran the code in 2015a, and both versions your code again run in comparable time. Interestingly, it was twice as fast in 2015a. :-(
I just finished running both versions of the code on a College Lab computer which also has R2015a installed. It is very similar to my personal PC (it is a Dell Optiplex 990 with the same operating system and memory). The result is the same: 7+ sec. for "Mod1", and 80+ sec. for "Mod2". So, this pretty much confirms that the College-wide installation of R2015a (by the same IT guys) has some sort of "bug", it appears. The IT guy is going to install R2015b on my PC Monday. I will report on the result afterwards. Thanks for all the help. The key was that no one outside this College sees any difference in execution time.

Connectez-vous pour commenter.

 Réponse acceptée

Try profiling the two codes to ensure the lines are being executed the same number of times in the different locations and to ensure that the line whose position is different in the two codes is the main consumer of the additional time in the second case.

2 commentaires

To profile, type
profile viewer
in the command window, type the name of the script in the field labeled "Run this code", and click on [Start profiling].
Cedric, I did as you instructed. Both versions of the program have the same number of calls to each statement in the program, but the amount of time spent on the single statement "H(w2,m,n)=.." increases by a factor of about 7 in the Mod2 version of the program. Several of the logic statements above this point are also impacted by a factor of 10 increase, but I cannot see any apparent connectivity of this behavior to the switch in location of the "H(w2,m,n)=.." statement. Again both programs have the identical number of calls to each statement. It is a bit frustrating.

Connectez-vous pour commenter.

Plus de réponses (1)

This appears to be a bug/limitation in the 64 bit JIT in MATLAB versions prior to R2015b. Other versions of MATLAB don't show the performance difference between the two line locations.
It does look like R2015b lost some performance when running this code. Look to future versions to recover the performance back to your best case example.
Looking at this code my first thought is that some reorganization and vectorization might help improve the performance and make it more understandable, allowing further optimizations and people not familiar with it to offer useful suggestions on performance and vectorization improvements.

1 commentaire

Philip, Thanks for finally solving this mystery. I have tried to be efficient with the coding, since speed is the biggest limitation in practical applications of this type of modeling code. I would appreciate any suggestions on where I might go to get some reorganization and vectorization guidance since execution speed will decide whether my work is of practical use or not. Thanks again for your help.

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by