How to find the amount of data generated/memory requirment for a program?
Afficher commentaires plus anciens
- How to know the computational memory requirement of a program?
- Also I would like to plot between computational time(run and time) and computational memory during a single run of a program.
- How to obtain a least computational time and least computational memory requirement for a given computational capacity?
Thanks in advance!
Réponse acceptée
Plus de réponses (1)
You can use memorywhos
function memory_in_use = memorywhos
%MONITOR_MEMORY_WHOS uses the WHOS command and evaluates inside the BASE
%workspace and sums up the bytes. The output is displayed in MB.
%
% Modified from
% https://de.mathworks.com/matlabcentral/answers/uploaded_files/1861/monitor_memory_whos.m
mem_elements = evalin('base', 'whos');
memory_in_use = sum([mem_elements(:).bytes])/2^20;
if nargout == 0
disp(['Memory in use ', num2str(memory_in_use, '%.6f'), ' MB'])
clear memory_in_use
end
1 commentaire
Steven Lord
le 6 Sep 2016
That's not necessarily accurate, or even close to accurate.
A = eye(1000);
f = @(x) A*x;
whos A f
So A is very large and f is very small.
clear A
whos
fws = functions(f)
fws.workspace{1}
The anonymous function handle f contains a copy of A, but that is not listed in the memory required by the variable f in whos.
"Hiding" data inside an anonymous function is not the only way to demonstrate this behavior; storing data in a private property of an object, putting it in a containers.Map object, storing it in the global workspace, making it a persistent variable inside a function, etc. are other techniques you can use that would make this underestimate how much memory is in use.
On the other hand, the copy-on-write behavior of MATLAB is a technique that could cause this to overestimate how much memory is in use.
A = ones(100);
B = A;
C = A;
whos A B C
This isn't actually using three times the amount of memory A uses, even though that's how it looks to whos.
Catégories
En savoir plus sur Whos dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!