stats
Return cached values and statistics for MemoizedFunction
object
Syntax
Description
Examples
Create a MemoizedFunction
object by memoizing the plus
function.
mf = memoize(@plus)
mf = MemoizedFunction with properties: Function: @plus Enabled: 1 CacheSize: 10
Call the memoized function several times. The first time you call the function with a particular set of inputs, MATLAB® caches the results.
a = mf(13,42); % calls plus; caches results b = mf(7,33); % calls plus; caches results c = mf(13,42); % does not call plus; returns cached results d = mf(5,120); % calls plus; caches results e = mf(13,42); % does not call plus; returns cached results f = mf(7,33); % does not call plus; returns cached results
Call the stats
function.
s = stats(mf)
s = struct with fields:
Cache: [1×1 struct]
MostHitCachedInput: [1×1 struct]
CacheHitRatePercent: 50
CacheOccupancyPercent: 30
Determine which sets of inputs you used the most.
s.MostHitCachedInput
ans = struct with fields:
Hits: 2
Input: {[13] [42]}
Obtain the cached results.
c = s.Cache
c = struct with fields:
Inputs: {{1×2 cell} {1×2 cell} {1×2 cell}}
Nargout: [1 1 1]
Outputs: {{1×1 cell} {1×1 cell} {1×1 cell}}
HitCount: [2 1 0]
TotalHits: 3
TotalMisses: 3
Display all sets of cached inputs and outputs alongside how many times MATLAB accessed the cached values.
T = cell2table([c.Inputs' c.Outputs'],'VariableNames',{'Inputs','Outputs'}); T.Times_Cache_Accessed = c.HitCount'
T=3×3 table
Inputs Outputs Times_Cache_Accessed
_________________ _______ ____________________
{[13]} {[ 42]} {[ 55]} 2
{[ 7]} {[ 33]} {[ 40]} 1
{[ 5]} {[120]} {[125]} 0
Input Arguments
Function with memoization semantics, specified as a
MemoizedFunction
object.
Output Arguments
MemoizedFunction
statistics, returned as a structure
containing these fields.
Field | Description |
---|---|
| Cached results, returned as a structure. If
|
| Inputs for the most accessed cached values, returned as a structure. The structure contains the following fields:
|
| Percentage of times an input was found in the
cache, returned as a double. This property is computed
by
|
| How full the cache is, returned as a double
representing a percentage. This property is computed by
|
Version History
Introduced in R2017a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)