Micro-cache: memoize/cache function results

버전 1.0.0.0 (5.21 KB) 작성자: Christian Kothe
A simple helper to avoid re-calculating the same results repeatedly.
다운로드 수: 249
업데이트 2012/1/12

라이선스 보기

This is a lightweight mechanism to memoize results of functions that are often repeatedly called with the same arguments. It is indended for small-scale situations -- i.e., the function is called only with a small variety of arguments, for example less than 100, and the arguments (as well as results) are not too big (e.g., no large matrices or data sets). If too many different calls are to be cached, hlp_microcache "forgets about" the oldest ones. Its memory is also lost after MATLAB is closed or after typing "clear all". Different places of a program can independently memoize results of their functions, by calling hlp_microcache with their own unique 'domain' identifier. The overhead is in the ballpark of MATLAB's num2str(), i.e., very low.

Example:

% if this line is executed for the first time, it is as slow as magic(2000)
m = hlp_microcache('test',@magic,2000);

% if it is executed a second time, it is ca. three orders of magnitude faster than m=magic(2000)
m = hlp_microcache('test',@magic,2000);

인용 양식

Christian Kothe (2026). Micro-cache: memoize/cache function results (https://kr.mathworks.com/matlabcentral/fileexchange/34565-micro-cache-memoize-cache-function-results), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2008a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Fortran with MATLAB에 대해 자세히 알아보기
버전 게시됨 릴리스 정보
1.0.0.0