End of function slow - Matlab Profiler
Show older comments
Hi,
I'm trying to optimize my program, and I'm encountering very curious results with the Profiler. It seems that the end statement in a function is taking significantly longer than any other statement.
Below is an image from the profiler output.
ks is a 1D vector, realKa is a boolean, and everything else is just a scalar.

As you can see, end takes up more time than the two most computationally intensive lines 190 and 198 combined. Why is this?
Note: I'm quite sure it is not because of the profiler, because the profiler said the total time spent in this function was 5.252 seconds, while adding up all the times and rounding up yields 2.47 seconds. Running my program without the profiler speeds things up by close to the difference of 2.782 seconds.
2 Comments
Muthu Annamalai
on 25 Jul 2013
According to your profiling results, ~ 1/3 of the calls to err() function do not enter the loop. Also I wonder if having function name, variable name, and the return value set to the same identifier has something to do with it.
I'd be more creative and use different names, assuming there isn't a shortage where you live :-)
Vince
on 25 Jul 2013
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations 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!