I recently trying to make a simple program that calculates FLOPS. Since c++
is fast enough so I think that worth a try to have close result.
When I compile it with Notepad++ plugins, NppExec
, it works fine, but i doesn't build it. When i build and run in CodeBlocks, it keep iterating and won't finish the process. So I go back to notepad++ and compile it again, then this time when I run it works fine, the iteration just elapsed a sec.
#include<iostream>
#include<conio.h>
#include<ctime>
#include<iomanip>
using namespace std;
int main(){
float a=1.0,b=2.0,var,j;
double flop;
clock_t start,end;
cout<<"\n Iterating...";
start=clock();
for(j=0;j<999999999;j++){ // Iterates 999999999 times
var=a*b+a/b; // <-- 5 Flops, or am I wrong?
}
end=clock();
cout<<"\n\n Calculating...";
double secs=((float)(end-start))/CLOCKS_PER_SEC;
flop=999999; // Actually is 999999999, but integer overflow in expression
flop=5*(flop*1000+999); // In the brackets I make the value to same as 999999999
// Multiply with 5 and basically get Flops here
flop/=secs; // To get the Flops in second, multiply with time elapsed
string prefix,fstr;
if(flop/1000000000>=1||flop/1000000000<1){
flop/=1000000000;
prefix="GFLOPS";
}
else if(flop/1000000000000>=1){
flop/=1000000000000;
prefix="TFLOPS";
}
cout<<"\n\n\n Floating-points Operations Per Second\n\n > "<<setprecision(3)<<flop<<" "<<prefix;
getch();
return 0;
}
If you know how to make the result more precise, go ahead, any answer will be appreciated!