I have a 2GB file. An average line has 15 char (max 50). When using:
#include <iostream>
#include <fstream>
#include <string>
void main()
{
std::ifstream input("myfile.txt");
std::string line;
while (std::getline(input, line))
{
}
return;
}
it takes ~ 320 seconds, whereas this Python code:
with open('myfile.txt', mode='r') as f:
for l in f:
semicolonpresent = ';' in l # do anything here, not important
takes less than one minute.
What is wrong in the C++ version I'm using?
Note: I've tried both many times, each one after a fresh reboot, or after many previous runs (so it might be in I/O cache), but I always get such order of magnitudes.
Note2: I compiled the C++ code on Windows 7/64, using:
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86
cl main.cpp