how to read the 150000 data from a txt file in a short period of time. I am now using getline and it costs about 23mins | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

how to read the 150000 data from a txt file in a short period of time. I am now using getline and it costs about 23mins

17th Nov 2017, 2:36 PM
Cheung Kim Fung
Cheung Kim Fung - avatar
4 Antworten
+ 2
What type of data are you reading and are you actually using all of the data that gets pulled or just particular data from the set?
17th Nov 2017, 2:47 PM
AgentSmith
+ 1
Line-by-line triggers a 'too much overhead' thought for me. I've seen faster (by orders of magnitude) reading large blocks (ideally a multiple of disk cluster size), then parse for delimiters in-memory. @Netkos is right to ask about the file + what you're doing though; my first response just comes from disliking line I/O. You could even have disk fragmentation, a busy system, a logic issue or flaky drive. To focus on code, can you show some in CodePlayground and maybe a couple data lines?
17th Nov 2017, 3:28 PM
Kirk Schafer
Kirk Schafer - avatar
0
something like surname, given name, telephone number and they are all string. I am now using getline(cin, input)
23rd Nov 2017, 6:45 AM
Cheung Kim Fung
Cheung Kim Fung - avatar
0
while (!myfile.eof()) { // GET IT getline(myfile, title, '\t'); getline(myfile, surname, '\t'); getline(myfile, givenName, '\t'); getline(myfile, phoneNumber, '\t'); getline(myfile, emailAddress, '\t'); getline(myfile, occupation, '\t'); getline(myfile, company); char* temp = new char[phoneNumber.length() + 1]; char* temp_2 = new char[dayOfBirth.length() + 1]; strcpy(temp, phoneNumber.c_str()); strcpy(temp_2, dayOfBirth.c_str()); count = Hash_1.get_Key1(phoneNumber, dayOfBirth); } Hash_1.getKey1 is a function for generating keys
23rd Nov 2017, 7:20 AM
Cheung Kim Fung
Cheung Kim Fung - avatar