MATLAB: Impact of functions on calculations time!

matlab function

First I apologize for my poor English, I have a question. It's important for me. My program in Matlab is too slow! I didn't use function in my program. do function reduce calculations time? or increase it? Thanks.

Best Answer

Refactoring the exact same code into functions should have next to no impact on the speed. If it does it would think it would be on the side of a slight decrease in speed.
If you are using classes then there is an overhead to class scope resolution for methods and properties so you have to be a little bit careful there not to slow your program down massively, but I doubt that is relevant in your case.
Using functions is definitely desirable though in general and would likely make it easy to run the profiler and understand and isolate where your code is slow (especially, for example, being able to time just a single function of your code rather than always the whole program at once).
If you are talking about using built-in functions to replace code you have written yourself then certainly they may make the code either faster or slower. It is impossible to say in a general case.
Related Question