分类: C/C++
2010-08-26 12:41:03
TCTimeCost timea; 测试结果,源文件条数:1741条,可以看到用块读比一行一行读快60倍
timea.Start();
char buf[1024*10];
int iFd = open("data.txt",O_RDONLY);
if(iFd == -1){
cout<<"open file:"<<"data.txt"<<" error!!!"<
}
int isize = 0;
int pos,pos2;
string slastrec,srec;
while((isize = read(iFd,buf,8192))>0){
//cout<<"slastrec.size="<
srec = slastrec + string(buf);
else
srec = buf;
//cout<<"srec="<
slastrec = "";
while((pos=srec.find("\n", pos))!= string::npos){
//cout<<"jf rec="<
}
int recsize = srec.size();
if(pos2
}
close(iFd);
cout<<"read file time:"<
ifstream iFile("data.txt");
while(iFile.good()){
iFile.getline(buf, sizeof(buf));
//cout<<"rec="<
iFile.close();
cout<<"fstream file time:"<
read file time:10516
fstream file time:657857