我有一个 C++ 代码,它计算 int 数据类型的阶乘、浮点数据类型的添加和每个函数的执行时间,如下所示:
long Sample_C:: factorial(int n)
{
int counter;
long fact = 1;
for (int counter = 1; counter <= n; counter++)
{
fact = fact * counter;
}
Sleep(100);
return fact;
}
float Sample_C::add(float a, float b)
{
return a+b;
}
int main(){
Sample_C object;
clock_t start = clock();
object.factorial(6);
clock_t end = clock();
double time =(double)(end - start);// finding execution time of factorial()
cout<< time;
clock_t starts = clock();
object.add(1.1,5.5);
clock_t ends = clock();
double total_time = (double)(ends -starts);// finding execution time of add()
cout<< total_time;
return 0;
}
现在,我想为“添加”功能测量 GFLOP。所以,请建议我将如何计算它。因为,我对 GFLOP 完全陌生,所以请告诉我我们是否可以为只有 foat 数据类型的函数计算 GFLOP?并且 GFLOPs 值也随着不同的功能而变化?