Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.
Escriba código que sea simple y legible, especialmente para la primera implementación. Si el código se optimiza de forma prematura, puede quedar innecesariamente complejo y no proporcionar una mejora de rendimiento significativa. Entonces, si la velocidad representa un problema, puede medir cuánto tarda el código en ejecutarse y crear un perfil para el código a fin de identificar sus cuellos de botella. Si es necesario, puede tomar medidas para mejorar el rendimiento.
MATLAB® gestiona automáticamente el almacenamiento de datos por usted. Sin embargo, si la memoria representa un problema, puede identificar los requisitos de la memoria y aplicar técnicas para utilizarla de forma más eficiente.
Measure the Performance of Your Code
Use the timeit
function or the stopwatch timer functions,
tic
and toc
, to time how long your
code takes to run.
Profile Your Code to Improve Performance
Use the Profiler to measure the time it takes to run your code and identify which lines of code consume the most time or which lines do not run.
Determine Code Coverage Using the Profiler
To determine how much of a file MATLAB executes when you profile it, run the Coverage Report.
Techniques to Improve Performance
To speed up the performance of your code, there are several techniques that you can consider.
Understand how MATLAB allocates memory to write code that uses memory more efficiently.
Strategies for Efficient Use of Memory
Reduce memory usage in your programs, use appropriate data storage, avoid fragmenting memory, and reclaim used memory.
Avoid Unnecessary Copies of Data
MATLAB can apply memory optimizations when passing function inputs by value.
Resolve “Out of Memory” Errors
MATLAB returns an error whenever it requests a segment of memory from the operating system that is larger than what is available.