필터 지우기
필터 지우기

cputime with kmeans return 0

조회 수: 1 (최근 30일)
Phu Lai
Phu Lai 2016년 12월 20일
답변: Walter Roberson 2016년 12월 20일
I am measuring the cputime taken by kmeans algorithm for each iteration using cputime feature. However, some iteration return cputime = 0. Here's my implementation:
load fisheriris;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Display', 'off');
results=[];
for i = 1:15
t=cputime;
[~,C] = kmeans(meas, 3, 'options',statset('MaxIter', 1),'Start',C, 'Display', 'off');
elapsedCPUTime=cputime-t;
results=[results;elapsedCPUTime];
end
This is the results I got for 15 iterations: 0, 0, 0.046875, 0, 0, 0, 0, 0, 0.03125, 0, 0, 0, 0, 0 ,0.03125. My first thought is that the computational time was too quick, hence 0 second. Is it true? If so, how can we achieve more precise cputime?
Thanks a lot.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 12월 20일
cpu time is difficult to measure, especially in a multi-processor machine that is running multiple programs (your system very likely has daemons or system processes running while you are running MATLAB.)
You should consider using timeit() or tic() and toc()

태그

Community Treasure Hunt

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

Start Hunting!

Translated by