Set or check a wall-clock timer. Calling
ticwithout an output argument sets the timer. Subsequent calls totocreturn the number of seconds since the timer was set. For example,tic (); # many computations later... elapsed_time = toc ();will set the variable
elapsed_timeto the number of seconds since the most recent call to the functiontic.If called with one output argument then this function returns a scalar of type
uint64and the wall-clock timer is not started.t = tic; sleep (5); (double (tic ()) - double (t)) * 1e-6 5Nested timing with
ticandtocis not supported. Thereforetocwill always return the elapsed time from the most recent call totic.If you are more interested in the CPU time that your process used, you should use the
cputimefunction instead. Theticandtocfunctions 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.)