End line taking huge amount of time in profiler
조회 수: 28 (최근 30일)
이전 댓글 표시
I was running a script in MatLab (2016a) and it was running incredibly slowly, I ran the profiler and found that two of the lines that were taking the most time were the end lines. This seems incredibly bizarre, what can I do to fix it and why is it so in the first place? Many Thanks
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154348/image.png)
댓글 수: 1
dpb
2016년 6월 22일
Note you've got two end statements at lines 24,25 that are called 4158 times; that double loop is the bottleneck. Now what's in there isn't shown but need to investigate what you're doing...perhaps dynamically reallocating an array or somesuch, maybe??? The key is it's not the end itself but what that is encompassing that the profiler can't separate to any finer resolution...
답변 (1개)
Philip Borghesani
2016년 6월 22일
Without seeing the full function all I can do is guess. Typically time shows up in end statements for workspace cleanup when exiting a function and for loop overhead in a for loop. There appears to be too much time in your end statements (for the number of times the line was hit) for it to be simple for loop overhead. I expect something in the code block is creating large objects or structures of objects and cleaning up or maintaining the loop index is taking a long time.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!