TIC_TOC
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
        toc
      
If toc is called without an output argument, it prints the elapsed time. or you can save the output from toc and print it yourself.
        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.

Licensing:

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

Languages:

TIC_TOC is available in a MATLAB version.

Related Data and Programs:

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.

Examples and Tests:

TIC_TOC_TEST:

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_RESOLUTION estimates the resolution of the TIC and TOC commands by calling N times and averaging.

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


Last revised on 20 May 2012