以下是测试代码:
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
int main(int argc, char **argv)
{
if (argc != 2)
{
cout << "syntax: benchmark <option>" << endl << "option can be r or w" << endl;
cout << "argc: " << argc << endl;
return 1;
}
const int count = 9000000;
vector<int> data(count);
if (argv[1][0] == 'w')
{
ofstream fout("test.txt");
for (int i = 0; i < count; i++)
{
fout << i << " ";
}
}
else if (argv[1][0] == 'r')
{
ifstream fin("test.txt");
for (int i = 0; i < count; i++)
{
fin >> data[i];
}
}
}
这段代码会自动生成 test.txt ,其中是 0 - 8999999 这 9000000 个数字。
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.