Function Reference
— Built-in Function: tic ()
— Built-in Function: toc ()

Set or check a wall-clock timer. Calling tic without an output argument sets the timer. Subsequent calls to toc return the number of seconds since the timer was set. For example,

          tic ();
          # many computations later...
          elapsed_time = toc ();

will set the variable elapsed_time to the number of seconds since the most recent call to the function tic.

If called with one output argument then this function returns a scalar of type uint64 and the wall-clock timer is not started.

          t = tic; sleep (5); (double (tic ()) - double (t)) * 1e-6
               5

Nested timing with tic and toc is not supported. Therefore toc will always return the elapsed time from the most recent call to tic.

If you are more interested in the CPU time that your process used, you should use the cputime function instead. The tic and toc functions report the actual wall clock time that elapsed between the calls. This may include time spent processing other jobs or doing nothing at all. For example,

          tic (); sleep (5); toc ()
               5
          t = cputime (); sleep (5); cputime () - t
               0

(This example also illustrates that the CPU timer may have a fairly coarse resolution.)