for loop running time analysis
3 views (last 30 days)
Show older comments
Profiler shows that "end" line takes a large part of the running time of for loop. Why? Do jump instructions really run longer than calculation process?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288222/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/288222/image.png)
0 Comments
Accepted Answer
Walter Roberson
on 15 May 2020
When MATLAB notices that patterns of code have been used that can be made more efficient by calling into the high-performance mathematically libraries such as MKL, then MATLAB does not execute the given code line-by-line, and it allocates the total time to the end-point of the section that it optimized. Also, the overhead of running the for loop is allocated against the end statement
0 Comments
More Answers (1)
rajat aggarwal
on 15 May 2020
Yes jump statement takes more time then usual line and here in your case you are using end statement in a loop. Jump statement hinders the workflow of a program. Usually Program counter jumps from one position to another position and start executing the instruction stored there. It requires time. Therefore jump statements take more time than usual statemtents.
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!