printf("cout time: %f seconds\n", (double)(end - start) / CLOCKS_PER_SEC); // 测试 printf start = clock(); for (int i = 0; i < 1000000; i++) { printf("%d\n", i); } end = clock(); printf("printf time: %f seconds\n", (double)(end - start) / CLOCKS_PER_SEC); ...
cout <<"printf : "<<1.0*(pri-co) / (CLOCKS_PER_SEC) <<"s"<< endl;return0; } 结果: cout :30.008000sprintf :29.687000s 5. cout、printf输出换行(对cout同时测试endl和\n) 代码: //test 5 : cout VS printf in endline#include<iostream>#include<cstdio>#include<ctime>#include<iomanip>us...
很快便锁定问题的症结在于输入输出,其实刚开始并不确定,虽然很早以前就知道cin,cout比scanf,printf要慢,可一直没在意,认为即使有差别也不会太大吧,但这次“血淋淋”的事实就是cin,cout就TLC,scanf,printf就AC了。于是,一个问题“cin,cout与scanf,printf速度上的差别到底有多大”便出现在脑海中。晚上跑步的时候,将...