tic - Start stopwatch timer - MATLAB (original) (raw)

Main Content

Syntax

Description

tic works with the toc function to measure elapsed time. The tic function records the current time, and the toc function uses the recorded value to calculate the elapsed time.

example

timerVal = tic stores the current time intimerVal so that you can pass it explicitly to thetoc function. Passing this value is useful when there are multiple calls to tic to time different parts of the same code.timerVal is an integer that has meaning only for thetoc function.

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.

Tips

Extended Capabilities

expand all

Usage notes and limitations:

Version History

Introduced before R2006a