Lesson 15: Comparing 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(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 elimintation 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! Others related commands are tic and toc.

It should be noted that, on timesharing machine, etime may not be a reliable measure of the eficiency of an algorithm since the rate of execution depends on how busy the computer is at that particular time when you execute your program.