MATLAB Functions for Elapsed Time

**TIC_TOC**
is a directory of MATLAB programs which
consider the MATLAB tic and toc functions for computing elapsed time.

MATLAB includes two functions tic and **TOC**. If **TIC**
is called before something is to be timed, and **TOC** is called
afterward, then **TOC** will either print the elapsed wallclock
time if its value is not being copied to a variable, or return the
value of the elapsed wallclock time to a variable.

To time an entire program, the simplest method to get the elapsed
wallclock time is to call tic before you run the program
and **toc** afterwards:

tic my_program tocIf

tic my_program wtime = toc fprintf ( 1, ' MY_PROGRAM took %f seconds to run.\n', wtime );

For parallel programming, the important thing to measure is the elapsed wallclock time. This can be found by subtracting an initial reading of the wallclock time from a final one.

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

**TIC_TOC** is available in
a MATLAB version.

TIMER, MATLAB programs which demonstrate how to compute CPU time or elapsed time.

TIMESTAMP, a MATLAB library which prints out the current YMDHMS date.

WTIME, a MATLAB library which returns a reading of the wall clock time in seconds.

**TIC_TOC_TEST**:

- tic_toc_test.m, calls all the tests.
- tic_toc_test_output.txt, the output file.
- timestamp.m, prints the YMDHMS date as a timestamp.

**TIC_TOC_PRINTING** calls TIC, and then immediately calls TOC several
times. If we call the "printing" TOC, then the cost of printing will be
added to each subsequent TOC. If we instead store the output of TOC and
print it later, we get a more reliable result.

- tic_toc_printing.m, compares two ways to estimate the tic/toc resolution;
- tic_toc_printing_test.m, calls tic_toc_printing.

**TIC_TOC_RESOLUTION** estimates the resolution of the TIC and TOC commands
by calling N times and averaging.

- tic_toc_printing.m, compares two ways to estimate the tic/toc resolution;
- tic_toc_printing_test.m, calls tic_toc_printing.

You can go up one level to the MATLAB source codes.