I'm trying to read lines using getline function in gcc on Ubuntu and MSVS on Windows. The time taken to process 200MB text file on Windows is 3 seconds whereas the time taken on Ubuntu is 0.1 second. Both are X64 Release builds.
Not sure why Windows is slower. Any reason for this? Is there any other getline function in Windows that matches the performance of that in Ubuntu?
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
int main()
{
string line;
int num = 0;
ifstream infile;
infile.open("testdata.txt");
if (infile.is_open())
{
while (!infile.eof()) // To get you all the lines.
{
getline(infile, line);
num++;
}
}
else
printf("file not found");
cout << num;
return 0;
}