Improving code performance by compiling
显示 更早的评论
Hello,
I'm coding a program where runtime is relevant, so I'm looking for ways to optimize performance. From what I've read here
the compiler / compiler SDK (don't really know the difference between the two) can create standalone apps that support most features - including graphics - but does not speed up the code since it is not compiled. The coder on the other hand can improve runtime, but does not support graphics (which I need). So in my case the only way to make use of compilation to speed up the program would be to put code into functions wherever possible and then compile those into mex files. Is that right?
4 个评论
Mohammad Sami
2021-3-18
If you have finished building your app, use the built in profiler, to profile you app in matlab. This will help you identify areas of bottlenecks. You can then try to optimize your code.
broken_arrow
2021-3-18
Mohammad Sami
2021-3-18
编辑:Mohammad Sami
2021-3-18
As you noted, compiling the app into standalone executable will not improve the performance beyond what you have already achieved in Matlab. The only thing you can do is to vectorize your code and to follow the optimization techniques which you can find on this forum or in the help page here.
broken_arrow
2021-3-19
采纳的回答
更多回答(1 个)
Pratheek
2025-11-6
0 个投票
Like Jan mentioned, write your code so that it is clear and easy to understand, especially on the first attempt. Avoid optimizing too early—complex code that tries to be fast from the start often does not improve performance enough to justify the loss in readability. Once it’s working, you can measure execution time and use profiling tools to locate performance bottlenecks. If speed becomes a concern, optimize only the sections that actually need improvement. MATLAB automatically manages memory for you, but if you run into memory limitations, you can evaluate how much memory your code uses and apply methods to reduce usage when necessary.
Refer the documentation for more details: https://www.mathworks.com/help/matlab/performance-and-memory.html
类别
在 帮助中心 和 File Exchange 中查找有关 Algorithm Design Basics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!