24,854
社区成员
发帖
与我相关
我的任务
分享
void test_write()
{
const int TEST_SIZE = 10000;
const char* c_plus_write_file = "c_plus_write_file.txt";
const char* c_write_file = "c_write_file.txt";
cout << "Test size :" << TEST_SIZE << endl;
//c++ style writing file
ofstream of(c_plus_write_file);
assert(of);
time_t start, end;
start = clock();
for (int i = 0; i < TEST_SIZE; ++i)
{
char tmp[10000];
tmp[0] = char(i);
of.write(tmp, 10000);
}
end = clock();
of.close();
cout << "C++ style: " << end - start << " ms" << endl;
//c style writing file
FILE* fp = fopen(c_write_file, "w");
start = clock();
for (int i = 0; i < TEST_SIZE; ++i)
{
char tmp[10000];
tmp[0] = char(i);
fwrite(tmp, 1, 10000, fp);
}
end = clock();
fclose(fp);
cout << "C style: " << end - start << " ms" << endl;
cin.get();
}
int main(){
test_write();
return 0;
}