I have large amount of tab delimited Flat File Table. I want to load all data in a 2D vector Container in Quicker time. I have given my code below. I checked my code with Ofast, Os and O2 Complexities. But It will take nearly 20 Seconds to load 100,000 records with 4 columns. But I want to load 500,000 records within 1 Second. How can I achieve it. ?
typedef vector <string> record_t;
typedef vector <record_t> table_t;
fstream& operator >> ( fstream& ins, record_t& r_record )
{
r_record.clear();
string s_line;
getline( ins, s_line );
stringstream ss( s_line );
string s_field;
while (getline( ss, s_field, '\t' ))
{
r_record.push_back( s_field );
}
return ins;
}
fstream& operator >> ( fstream& ins, table_t& t_data )
{
t_data.clear();
record_t r_record;
while (ins >> r_record)
{
t_data.push_back( r_record );
}
return ins;
}
fstream fs("somesamplefile.txt",ios::in);
table_t table;
fs>>table;
Time Difference is :
Os 22.860000 Seconds
Ofast 21.320000 Seconds
O2 22.660000 Seconds