Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Performance and Memory

Improve performance; identify and 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.

Functions

timeitMeasure time required to run function
ticStart stopwatch timer
tocRead elapsed time from stopwatch
cputimeElapsed CPU time
profileProfile execution time for functions
benchMATLAB benchmark
memoryDisplay memory information
inmemNames of functions, MEX-files, classes in memory
packConsolidate workspace memory
memoizeAdd memoization semantics to function handle
MemoizedFunctionCall memoized function and cache results
clearAllMemoizedCachesClear caches for all MemoizedFunction objects

Topics

Measure and Profile Code

Measure Performance of Your Program

To time how long your code takes to run, use the timeit function or the stopwatch timer functions, tic and toc.

Profile to Improve Performance

To identify which lines of code consume the most time or which lines MATLAB does not run, profile your code.

Use Profiler to Determine Code Coverage

To determine how much of a file MATLAB executes when you profile it, run the Coverage Report.

Improve Performance

Techniques to Improve Performance

To speed up the performance of your code, there are several techniques that you can consider.

Identify and Reduce Memory Requirements

How MATLAB Allocates Memory

Understand how MATLAB allocates memory to write code that uses memory more efficiently.

Strategies for Efficient Use of Memory

Reduce the amount of memory your program requires, determine the appropriate data storage, avoid fragmenting memory, and reclaim used memory.

Resolve “Out of Memory” Errors

MATLAB generates an Out of Memory message whenever it requests a segment of memory from the operating system that is larger than what is available.

Related Information

Was this topic helpful?