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.

Apps

Profiler Run code and measure execution time to improve performance

Functions

expand all

tic Start stopwatch timer
toc Read elapsed time from stopwatch
cputime CPU time used byMATLAB
timeit Measure time required to run function
profile Profile execution time for functions
bench MATLABbenchmark
memory Memory information
inmem Names of functions, MEX files, and classes in memory
memoize Add memoization semantics to function handle
MemoizedFunction Call memoized function and cache results
clearAllMemoizedCaches Clear caches for allMemoizedFunction对象

Topics

Measure and Profile Code

Improve Performance

Identify and Reduce Memory Requirements

Related Information