flops

Purpose

Count floating-point operations.

Synopsis

f = flops
flops(0)

Description

f = flops returns the cumulative number of floating-point operations.

flops(0) resets the count to zero.

Examples

If A and B are real n-by-n matrices, some typical flop counts for different operations are

---------------------
Operation  Flop Count  
---------------------
A+B        n^2         
A*B        2*n^3       
A^100      99*(2*n^3)  
lu(A)      (2/3)*n^3   
---------------------
MATLAB's version of the LINPACK benchmark is

n = 100;
A = rand(n,n);
b = rand(n,1);
flops(0)
tic;
x = A\b;
t = toc
megaflops = flops/t/1.e6

Algorithm

It is not feasible to count all the floating-point operations, but most of the important ones are counted. Additions and subtractions are each one flop if real and two if complex. Multiplications and divisions count one flop each if the result is real and six flops if it is complex. Elementary functions count one if real and more if complex.