2015年2月18日 星期三
A program to read CSV file with time elapsed reported
File:
"0#AU113554908=",6261,88,214
" const
{
return vTokens[index];
}
size_t size() const
{
return vTokens.size();
}
void readNextRow(istream& str)
{
string line;
getline(str, line);
stringstream lineStream(line);
string token;
vTokens.clear();
while(getline(lineStream, token, ','))
{
vTokens.push_back(token);
}
}
private:
vector<string> vTokens;
};
istream& operator>>(istream& str, CSVRow& data)
{
data.readNextRow(str);
return str;
}
class Timer
{
string s;
clock_t t;
public:
Timer(string s="") : t(clock()), s(s) {}
~Timer()
{
cout << "Function " + s + " elapsed in seconds [" << double(clock() - t) / CLOCKS_PER_SEC << "]" << '\n';
};
};
class Instrument
{
public:
string name;
int pe;
int recordType;
int exchangeID;
Instrument():name(""), pe(0), recordType(0), exchangeID(0) {}
Instrument (const string & name, int pe, int recordType, int exchangeID)
: name(name), pe(pe), recordType(recordType), exchangeID(exchangeID) {}
};
void TestRouteine(const string & filepath, vector<Instrument> & vInstruments)
{
volatile Timer timer("ReadCSV");
vInstruments.reserve(40000000);
ifstream fs(filepath);
CSVRow row;
while (fs >> row)
{
vInstruments.push_back(Instrument(row[0], atoi(row[1].c_str()), atoi(row[2].c_str()), atoi(row[3].c_str())));
}
cout << "size: [" << vInstruments.size() << "]" << endl;
}
int main()
{
vector<Instrument> vInstruments(40000000);
TestRouteine("../InstradayWS/pen201502131002.txt", vInstruments);
system("PAUSE");
}
訂閱:
張貼留言 (Atom)
2007 to 2023 HP and Dell Servers Comparison
HP Gen5 to Gen11 using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...
-
https://www.tutorialspoint.com/ Q Data Types There are a lot of data types in Q, including boolean byte short int long real float cha...
-
CME MDP 3.0 Market Data http://www.cmegroup.com/confluence/display/EPICSANDBOX/CME+MDP+3.0+Market+Data CME Market Data Platform has 3 ...
-
On CentOS 7, using yum install gives you cmake version 2.8.11 [root@thrift1 ~]# cat /etc/*release CentOS Linux release 7.2.1511 (Core) ...
沒有留言:
張貼留言