0 測試目標
測試三個計算,是寫在一個等式快,還是分開快。
1、測試代碼:
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <ctime>
#include <sstream>
// #include <fcntl.h>
using namespace std;
double f(){
int x=3;
return 3*100;
}
double g(double y){
return y*100;
}
double h(double x, double y)
{
return x*y;
}
int main()
{
int start = clock();
double a;
double b;
double c;
for(int i=0;i<1000000000;i++){
//方案1
// c = h(f(),g(f()));
//方案2
a = f();
b = g(a);
c = h(a,b);
}
cout<<" the time cost is"<<(" %.3lf\n", double(clock() - start) / CLOCKS_PER_SEC);
return 0;
}
2 測試結果
3、 測試結論
方案二更快一些