Comparing the Efficiency of ALgorithms: FLOPs and ETIME

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(O)

will reset flops to 0. Hence, entering

 
        flops(O) 

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 for more information). For example, given two such times tl and t2, the command

 
        etime(t2,tl)

gives the elapsed time from tl to t2. One can also, for example, measure the time required to solve a given linear system A = b, using Gaussian elimination as follows:

        time = clock; x = A\b; time = etime(clock,time)

You may wish to compare this time--and flop count--with that for solving the system using this command:

  
        x = inv(A)*b;


Other Matlab Hints

Click on an item listed below to access additional MATLAB-related hints.


Return to ACS home page.


Please send comments and suggestions to

consult@rpi.edu