cputime and tic...toc: high time difference

조회 수: 34 (최근 30일)
Viviana Arrigoni
Viviana Arrigoni 2019년 2월 7일
답변: Steven Lord 2019년 2월 7일
cputime and tic...toc are giving very different execution times. I am doing:
function[time, output2] = foo(input1, input2)
start = cputime;
tic;
...some computation
toc
tic;
...some computation
toc
...eccetera
tic;
...some computation
toc
time = cputime - start;
end
and I get this:
[t, ~] = foo(input1, input2)
Elapsed time is 0.564095 seconds.
Elapsed time is 119.898174 seconds.
Elapsed time is 76.127796 seconds.
Elapsed time is 3.465138 seconds.
Elapsed time is 0.240975 seconds.
t =
376.4200
that doesn't sum up to the total time at all. Why is it that? There are no code lines exluded between tic...tocs

답변 (1개)

Steven Lord
Steven Lord 2019년 2월 7일
See the "The cputime Function vs. tic/toc and timeit" section on this documentation page. One potential big difference is how many threads are working and for how much of the time they're working versus sitting idle waiting for something to do.

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by