toc
Read elapsed time from stopwatch
Description
toc
reads the elapsed time since the stopwatch timer started
by the call to the tic
function. MATLAB® reads the internal time at the execution of the toc
function and displays the elapsed time since the most recent call to the
tic
function without an output. The elapsed time is expressed
in seconds.
toc(
displays the elapsed time
since the call to the timerVal
)tic
function corresponding to
timerVal
.
elapsedTime = toc
returns the elapsed time since the most
recent call to the tic
function.
Examples
Input Arguments
Tips
Consecutive calls to the
toc
function with no input return the elapsed time since the most recent call totic
. This property enables you to take multiple measurements from a single point in time.Consecutive calls to the
toc
function with the sametimerVal
input return the elapsed time since thetic
function call that corresponds totimerVal
.Sometimes programs run too fast for
tic
andtoc
to provide useful data. If your code is faster than 1/10 second, consider measuring it running in a loop, and then average to find the time for a single run. For more information, see Measure the Performance of Your Code.The following actions result in unexpected output:
- Using
tic
andtoc
to timetimeit
- Using
tic
andtoc
within a function timed bytimeit
- Using
Extended Capabilities
Version History
Introduced before R2006a