cputime and tic...toc: high time difference

18 ビュー (過去 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 Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by