toc - Read elapsed time from

stopwatch - MATLAB (original) (raw)

Main Content

Read elapsed time from stopwatch

Syntax

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 thetic function without an output. The elapsed time is expressed in seconds.

example

toc([timerVal](#bswh%5Fpb-1-timerVal)) displays the elapsed time since the call to the tic function corresponding totimerVal.

elapsedTime = toc returns the elapsed time since the most recent call to the tic function.

example

elapsedTime = toc([timerVal](#bswh%5Fpb-1-timerVal)) returns the elapsed time since the call to the tic function corresponding totimerVal.

example

Examples

collapse all

Measure the time required to create two random matrices.

tic A = rand(12000,4400); B = rand(12000,4400); toc

Elapsed time is 0.805683 seconds.

Measure the elapsed time since a call to the tic function at different points of the program.

tic A = rand(12000,4400); B = rand(12000,4400); toc

Elapsed time is 0.769707 seconds.

Elapsed time is 0.860179 seconds.

Use a pair of tic and toc calls to report the total time required for element-by-element matrix multiplication; use another pair to report the total runtime of your program.

tStart = tic; % pair 2: tic n = 10; T = zeros(1,n); for i = 1:n A = rand(12000,4400); B = rand(12000,4400); tic % pair 1: tic C = A.*B; T(i)= toc; % pair 1: toc end tMul = sum(T)

tEnd = toc(tStart) % pair 2: toc

The variable tMul includes the total time spent on multiplication. tEnd specifies the elapsed time since the call to the tic function at the beginning of the program.

Input Arguments

collapse all

Value of the internal timer saved from a previous call to thetic function, specified as a scalar of typeuint64.

Tips

Extended Capabilities

expand all

Usage notes and limitations:

Version History

Introduced before R2006a