Order of magnitude (10 times greater) execution time resulting from order of computations in a script file that are otherwise identical.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Robert Eli
am 24 Sep. 2015
Kommentiert: Robert Eli
am 25 Sep. 2015
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 Kommentare
the cyclist
am 24 Sep. 2015
I ran the code in 2015a, and both versions your code again run in comparable time. Interestingly, it was twice as fast in 2015a. :-(
Akzeptierte Antwort
Steven Lord
am 24 Sep. 2015
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 Kommentare
Cedric
am 24 Sep. 2015
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].
Weitere Antworten (1)
Philip Borghesani
am 25 Sep. 2015
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.
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!