版本比较
cout与printf写速度比较
正文
增加 11 行删除 11 行
1234566789108 行未改动1920212223232425262725 行未改动535455565757585960614 行未改动6667686970707172737412 行未改动878889909191929394954 行未改动10010110210310410410510610710815 行未改动1241251261271281281291301311324 行未改动13713813914014114114214314414513 行未改动1591601611621631631641651661678 行未改动17617717817918018018118218318414 行未改动19920020120220320320420520620739 行未改动### 0.前置环境:
#### 计算机配置:CPU : i5 7500
RAM : 8G RAM : 8G
系统:Win7 64位
测试硬盘:intel 256G SSD8 行未改动#include <iostream>#include <cstdio>#include <ctime>using namespace std;int T = 10000000;//1e7 int T = 10000000;//1e7clock_t st, co, pri;signed main(){ freopen("waste.out","w",stdout); st = clock();25 行未改动#include <iostream>#include <cstdio>#include <ctime>using namespace std;const int T = 10000000;//1e7 const int T = 10000000;//1e7clock_t st, co, pri, pus, puc;signed main(){ freopen("waste.out","w",stdout); st = clock();4 行未改动 for(int i = 1; i <= T; ++i){ printf("%d", i); } pri = clock();
freopen("result.out","w",stdout); cout << "cout : " << 1.0*(co-st) / (CLOCKS_PER_SEC) << "s" << endl; cout << "printf : " << 1.0*(pri-co) / (CLOCKS_PER_SEC) << "s" << endl; return 0;12 行未改动#include <iostream>#include <cstdio>#include <ctime>using namespace std;const int T = 10000000;//1e7 const int T = 10000000;//1e7clock_t st, co, pri, pus, puc;signed main(){ freopen("waste.out","w",stdout); st = clock();4 行未改动 for(int i = 1; i <= T; ++i){ printf("%lld", 1ll*i*T); } pri = clock();
freopen("result.out","w",stdout); cout << "cout : " << 1.0*(co-st) / (CLOCKS_PER_SEC) << "s" << endl; cout << "printf : " << 1.0*(pri-co) / (CLOCKS_PER_SEC) << "s" << endl; return 0;15 行未改动#include <cstdio>#include <ctime>#include <iomanip>using namespace std;const int T = 10000000;//1e7 const int T = 10000000;//1e7clock_t st, co, pri, pus, puc;signed main(){ freopen("waste.out","w",stdout); st = clock();4 行未改动 for(double i = 1; i <= T; ++i){ printf("%.6lf", 11.45141919 * i); } pri = clock();
freopen("result.out","w",stdout); cout << "cout : " << 1.0*(co-st) / (CLOCKS_PER_SEC) << "s" << endl; cout << "printf : " << 1.0*(pri-co) / (CLOCKS_PER_SEC) << "s" << endl; return 0;13 行未改动#include <cstdio>#include <ctime>#include <iomanip>using namespace std;const int T = 10000000;//1e7 const int T = 10000000;//1e7clock_t st, co, el, pri, pus, puc;signed main(){ freopen("waste.out","w",stdout); st = clock();8 行未改动 for(int i = 1; i <= T; ++i){ printf("\n"); } pri = clock();
freopen("result.out","w",stdout); cout << "cout : " << 1.0*(co-st) / (CLOCKS_PER_SEC) << "s" << endl; cout << "endl : " << 1.0*(el-co) / (CLOCKS_PER_SEC) << "s" << endl; cout << "printf : " << 1.0*(pri-el) / (CLOCKS_PER_SEC) << "s" << endl;14 行未改动#include <iostream>#include <cstdio>#include <ctime>using namespace std;int T = 10000000;//1e7 int T = 10000000;//1e7clock_t st, co, pri, pus, puc;signed main(){ freopen("waste.out","w",stdout); st = clock();39 行未改动