Prestazioni e memoria
Scrivere il codice in modo che sia semplice e leggibile, soprattutto per la prima implementazione. Il codice ottimizzato prematuramente può risultare inutilmente complesso senza fornire un vantaggio significativo in termini di prestazioni. Successivamente, se la velocità è un problema, è possibile misurare il tempo di esecuzione del codice e tracciarne il profilo per identificare i colli di bottiglia. Se necessario, si possono adottare misure per migliorare le prestazioni.
MATLAB® gestisce automaticamente la memorizzazione dei dati. Tuttavia, se la memoria costituisce un problema, è possibile identificare i requisiti di memoria e applicare tecniche per utilizzarla in modo più efficiente.
App
Profiler | Run code and measure execution time to improve performance |
Funzioni
Argomenti
Misura e codice del profilo
- Measure the Performance of Your Code
Use thetimeit
function or the stopwatch timer functions,tic
andtoc
, 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. - Measure Code Complexity Using Cyclomatic Complexity
Quantify code complexity based on cyclomatic complexity.
Miglioramento delle prestazioni
- Techniques to Improve Performance
To speed up the performance of your code, there are several techniques that you can consider.
Identificazione e riduzione dei requisiti di memoria
- How MATLAB Allocates Memory
Write more memory-efficient code by understanding how MATLAB allocates memory. - 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
Troubleshoot errors when MATLAB cannot allocate the requested memory.