toc
Read elapsed time from stopwatch
Description
toc
reads the elapsed time since the stopwatch timer started by the call to thetic
function. MATLAB®reads the internal time at the execution of thetoc
function and displays the elapsed time since the most recent call to thetic
function without an output. The elapsed time is expressed in seconds.
toc(
displays the elapsed time since the call to thetimerVal
)tic
function corresponding totimerVal
.
elapsedTime = toc
returns the elapsed time since the most recent call to thetic
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, seeMeasure 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