next up previous contents
Next: Polynomials Up: Further MATLAB Previous: Debugging

Efficiency Testing, Times and Dates

Most of the time spent in an algorithm is consumed by floating-point operations; integer operations are relatively instantaneous. The special function flops tracks the number of floating-point operations performed. It begins at zero, and flops(0) will reset it. Therefore, flops(0); operation(s); flops gives a reasonable measure of the effort spent in operation(s).

Alternatively, you may wish to time your operations. Use tic to start a stopwatch and toc to read it. So tic; operation(s); toc gives the number of seconds during operation(s). However, since your computer was probably doing other things during that time, this is not a very reliable indication of the operations' efficiency; repeat it and see.

A better method of measuring time consumption is given by cputime, which is a non-resettable counter giving the CPU time used by MATLAB since it started:
cpu = cputime; operation(s); disp(cputime - cpu).

If you simply wish to see the time, clock offers a wall clock giving a [year month day hour minute second] vector, and etime gives the time elapsed between two such vectors. A day-month-year string is returned by date.



sepherke
Sat Mar 21 21:42:28 EST 1998