最近、FLOPS を計算する簡単なプログラムを作成しようとしています。十分に速いのでc++
、近い結果を出すために試してみる価値があると思います。
Notepad++ プラグインでコンパイルすると、NppExec
正常に動作しますが、ビルドしません。CodeBlocks でビルドして実行すると、反復が続き、プロセスが完了しません。そのため、notepad++ に戻って再度コンパイルすると、今回は正常に動作し、反復が 1 秒経過しただけです。
#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;
}
結果をより正確にする方法を知っている場合は、先に進んでください。どんな回答でも大歓迎です!