toc

Reads the stopwatch started by tic.

Category: Software Development Tools > Performance and Memory

Syntax

toc

Prints the seconds elapsed since the last tic.

t = toc

Returns the elapsed seconds instead of printing them.

Description

toc does not stop the timer: calling it again later reports a longer time since the same tic. Without an output argument it prints a line of the form Elapsed time is 0.01 seconds., so most code asks for the number and formats it itself.

Calling toc before any tic is an error.

Output arguments

t
Elapsed time in seconds, a double.

Example

Two readings

tic
x = sum(1:1e6);
t1 = toc;
y = sum(1:1e6);
t2 = toc;
disp(t2 >= t1)
Output
   1

See also

tic timeit cputime clock