필터 지우기
필터 지우기

Best way to do memory testing?

조회 수: 12 (최근 30일)
Shaun VanWeelden
Shaun VanWeelden 2013년 1월 31일
Hi,
My name is Shaun VanWeelden and I am working on a project to look at script performance. A large part of what I do is gather code to evaluate and see what errors are thrown, etc. I also try and do performance testing (using tic toc) and memory usage. We currently do memory testing the following way:
%Get initial memory being used
[user, sys] = memory ;
mStart = user.MemUsedMATLAB ;
%Get initial start time
tic
%Run the actual script, the 'evalc" suppresses all output,
%do "eval" without the c to see program output
evalc(the script);
%Figure out how long script took to run
time=toc;
%Calculate total memory used and add it to the cell array
[user, sys] = memory ;
mtotal = user.MemUsedMATLAB - mStart;
But this has provided very inconsistent results due to the large number of other things going on inside the testing script. I was wondering if there was a better way to get the individual scripts we are testing’s memory use.
Thank you and let me know if you have any additional questions!
-Shaun VanWeelden
  댓글 수: 2
Shashank Prasanna
Shashank Prasanna 2013년 1월 31일
what does a typical "the script" look like?
Shaun VanWeelden
Shaun VanWeelden 2013년 1월 31일
Almost anything to be honest, lets just say if I wanted to run every product demo and evaluate it or something like that, it needs to be a pretty flexible program, whats your ideas? Even if it won't work completely with what I am trying to do

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2013년 1월 31일
A lot of important details of the memory usage cannot be measured by calling memory before and after calling a script or a function. Example:
function out = func1
out = rand(1000, 1000);
for ii = 1:numel(out)
out(ii) = sqrt(sin(abs(out(ii) - 1)));
end
end
function out = func2
tmp = rand(1000, 1000);
out = sqrt(sin(abs(tmp - 1)));
end

추가 답변 (2개)

Image Analyst
Image Analyst 2013년 2월 1일
Did you see the "profile" function in the help?
  댓글 수: 1
Shaun VanWeelden
Shaun VanWeelden 2013년 2월 1일
Very helpful, thank you!

댓글을 달려면 로그인하십시오.


Shashank Prasanna
Shashank Prasanna 2013년 2월 1일
Since we are talking undocumented, do check out feature('memstats') I am not sure how you will use this, but it gives a lot more information than memory does.
  댓글 수: 1
Cedric
Cedric 2013년 2월 1일
편집: Cedric 2013년 2월 1일
Interesting to compare to structs returned by memory() ..
>> T = evalc('feature(''memstats'')') ;
>> str2mat(regexp(T, '(?<=Use:\s*)\d+', 'match'))

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by