End line taking huge amount of time in profiler

14 views (last 30 days)
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
  1 Comment
dpb
dpb on 22 Jun 2016
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...

Sign in to comment.

Answers (1)

Philip Borghesani
Philip Borghesani on 22 Jun 2016
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.

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!