debug的時候需要等很長時間讀模型,查資料發現了兩種快速讀取大文件的方法。
test 1:每次讀一個字符串
test 2、3一次讀取整個文件
{//test 1
string buf;
clock_t start = clock();
ifstream fin(objpath);
while (fin >> buf);
fin.close();
clock_t end = clock();
cout << "time : " << ((double)end - start) / CLOCKS_PER_SEC << "s\n";
}
{//test 2
clock_t start = clock();
ifstream fin(objpath, std::ios::binary);
vector<char> buf(fin.seekg(0, std::ios::end).tellg());
fin.seekg(0, std::ios::beg).read(&buf[0], static_cast<std::streamsize>(buf.size()));
fin.close();
clock_t end = clock();
cout << "time : " << ((double)end - start) / CLOCKS_PER_SEC << "s\n";
}
{//test 3
clock_t start = clock();
ifstream fin(objpath);
stringstream buf;
buf << fin.rdbuf();
fin.close();
clock_t end = clock();
cout << "time : " << ((double)end - start) / CLOCKS_PER_SEC << "s\n";
}
文件大小為112M,花費的時間分別為:
time : 36.809s time : 0.092s time : 4.213s
於是將loader改成了第二種。
