I want to record how much time Matlab uses while running a programming. If I use cputime, the result is 94.28 while the result of using tic, toc is 28.02. I feel that 28.02 is more accurate.
So I'm wondering what's the difference between cputime and tic, toc.
Thanks in advance.
> I want to record how much time Matlab uses while running a programming.
> If I use cputime, the result is 94.28 while the result of using tic, toc
> is 28.02. I feel that 28.02 is more accurate.
> So I'm wondering what's the difference between cputime and tic, toc.
"cputime returns the total CPU time (in seconds) used by your MATLAB
application from the time it was started."
On the other hand, toc returns the time since the last tic .
So CPU time is larger than the elapsed real time?
Historically, the feirst versions of TIC/TOC measured
the elapsed time, while CPUTIME could be used to measure
the time the CPU spent on a particular task:
tstart = cputime;
doSomething;
tSpentOnDoingSomething = cputime - tstart;
Over time, multithread CPUs became more and more
widespread and somebody realized that no one cares
for elapsed time - it varies with all kinds of
random factors across the system. So TIC/TOC was
changed to instead display the time the CPU speds
on the task.
Rune
>
> So CPU time is larger than the elapsed real time?
Possibly with multicore CPU. But please don't take literally my world on that.
Bruno
Not that I'm aware of, tic/toc still displays the elapsed time, not CPU.
Bruno
I remember somebody fom TMW fiercly correcting me when I said
that, some time ago:
http://groups.google.com/group/comp.soft-sys.matlab/msg/741d1e08b74ca9de
I would hope somebody from TMW will chime in and unequivocally
state what is the actual case...
Rune
> tic; pause(10); toc
with monitoring CPU activity shows low CPU activity, and still toc will return ~10s
Bruno