对比 vc 与c# 读取 文件效率的问题
宙斯之神 2013-01-02 12:53:48 我准备读取一个40M的文件,每行都是一个整形数。
用studio 2010 的 c++ 写的代码如下,
vector<int> vui;
ifstream readfile("D:\\aa.txt");
while (!readfile.eof())
{
readfile.getline(charbuffer,25);
int a = atoi(charbuffer);
vui.push_back(a);
}
readfile.close();
用2010的c#的代码如下
StreamReader sr = new StreamReader("D:\\aa.txt",Encoding.Default);
string s;
List<int> li = new List<int>();
while ((s = sr.ReadLine()) != null)
{
li.Add(Convert.ToInt32(s));
}
两个程序都用debug模式执行的,发现读取文件vc用了10秒钟,而c#只用了2秒钟,
所以我很疑惑为何vc执行起来要慢:
1. 是我写的c++代码有问题吗?
2. 是不是我对vc的优化设置有问题?
3. 两个都是在2010上执行的,我总觉得c++的效率应该更高一些
4. 即使我把vc的用release版本执行 也只能跑到3秒多
欢迎大家讨论