Main Content

Performance and Memory

Profile code, improve performance, reduce memory requirements

Write your code to be simple and readable, especially for the first implementation. Code that is prematurely optimized can be unnecessarily complex without providing a significant gain in performance. Then, if speed is an issue, you can measure how long your code takes to run and profile your code to identify bottlenecks. If necessary, you can take steps to improve performance.

MATLAB® handles data storage for you automatically. However, if memory is an issue, you can identify memory requirements and apply techniques to use memory more efficiently.


ProfilerRun code and measure execution time to improve performance


expand all

ticStart stopwatch timer
tocRead elapsed time from stopwatch
cputimeCPU time used by MATLAB
timeitMeasure time required to run function
profileProfile execution time for functions
benchMATLAB benchmark
memoryMemory information
inmemNames of functions, MEX files, and classes in memory
memoizeAdd memoization semantics to function handle
MemoizedFunctionCall memoized function and cache results
clearAllMemoizedCachesClear caches for all MemoizedFunction objects


Measure and Profile Code

Improve Performance

Identify and Reduce Memory Requirements

Related Information