cputime and tic...toc: high time difference

18 views (last 30 days)
Viviana Arrigoni
Viviana Arrigoni on 7 Feb 2019
Answered: Steven Lord on 7 Feb 2019
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

Answers (1)

Steven Lord
Steven Lord on 7 Feb 2019
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.

Categories

Find more on Performance and Memory in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!