Two measures of the efficiency of an algorithm are the number of floating point operations (flops) performed and the elapsed time.
The MATLAB function flops keeps a running total of the flops performed. The command flops(0) (not flops = 0!) will reset flops to 0. Hence, entering flops(0) immediately before executing an algorithm and flops immediately after gives the flop count for the algorithm.
The MATLAB function clock gives the current time accurate to a hundreth of a second (see help clock). Given two such times t1 and t2, etime(t2,t1) gives the elapsed time from t1 to t2. One can, for example, measure the time required to solve a given linear system Ax=b using Gaussian elimination as follows:
t = clock; x = A \ b; time = etime(clock,t)You may wish to compare this time-and flop count-with that for solving the system using x = inv(A)*b;. Try it. Version 4.0 has the more convenient tic and toc.
It should be noted that, on timesharing machines, etime may not be a reliable measure of the efficiency of an algorithm since the rate of execution depends on how busy the computer is at the time.