cputime and tic...toc: high time difference

17 次查看(过去 30 天)
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