# Calculating Floating point Operations Per Second(FLOPS) and Integer Operations Per Second(IOPS)

I am trying to learn some basic benchmarking. I have a loop in my Java program like,

float a=6.5f;
int b=3;
for(long j=0; j<999999999; j++){
var = a*b+(a/b);
}//end of for


My processor takes around 0.431635 second to process this. How would I calculate processor speed in terms of Flops(Floating point Operations Per Second) and Iops(Integer Operations Per Second)? Can you provide explanations with some steps?

• Each loop is 3 FO, you know how many loops where done and the time. Do the math. Or check out the benchmarks at cs.bell-labs.com/cm/cs/pearls/appmodels.html (in C, but should give you an idea how to do it in Java). Commented Jan 25, 2013 at 7:22

It really depends on the optimizer. If you compile it with optimization, it might get rid of the loop, and then it will take rather less than 0.431635 seconds. Otherwise, it seems like you have four to five floating point instructions per iteration (including int to float conversion, once or twice, depending on the optimizer), so $4\cdot10^9$ or $5\cdot10^9$ in total. Divide this by 0.431635 to get your FLOPS, which will be around $10^{10}$, or 10 GFLOPS.

Our approach depends somewhat on which floating point operations we will be counting. I think it makes sense to include additions, multiplications, divisions, and casts. We will count each as one floating point operation.

In each loop, we have one add, one multiply, one divide, and two casts. (Perhaps the casting will be optimized--I'll assume not.) So each loop has $5$ floating point operations. The loop executes $999999999$ times, so we are performing $5*999999999$ floating point operations.

Since the program takes $0.431635$ seconds to execute, we have

$$\frac{\frac{5 flop}{iteration} * 999999999 iterations}{0.431635s} = 11583861352.8 \frac{flop}{s} = 11.58 \frac{Gflop}{s}$$

• You're making a lot of assumptions about the compiler, here. All kinds of things could be optimized away. (The whole loop body, for example...) Commented Feb 6, 2014 at 0:24

For C, Bentley's "Programming pearls" discusses some pitfalls and gives an (oldish) program to measure costs of several operations. For Java and other JITed languages it's more of a challenge, as the first run of the operation will get it compiled to native code and run that way.

In general, the only really relevant benchmark is running your program with a set of representative data and measure.

Grab a copy of Bentley's book (or start looking over it's webpage). You'll learn more about programming than you'd believe possible.