End line taking huge amount of time in profiler

31 次查看(过去 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
  1 个评论
dpb
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
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.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by