Hi, experts!
Recently, I have found that std::getline(fstream, string) used in Cling of root6.14.00 become much slower than root6.13.02.
Here is my codes for testing:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
void csvfileGetline()
{
string filepath = "/Users/yichunzh/DataAnalysis/All_Site_ChiST/";
string csvFileName = filepath + "All-2018-05_UID.csv";
ifstream fp;
fp.open(csvFileName.c_str(), ios::in|ios::binary);
if (!fp)
cout<< "Problem when opening the file: "<< csvFileName<< endl;
//variables to get data from csv file
string line;
int entries = 0;
while(!fp.eof() && fp.peek() != EOF)
{
line.clear();
getline(fp, line);
if (0 == entries%1000000)
cout<< "******** "<< entries<< " Currenttime: "<< TDatime().AsSQLString()<< " ********"<< endl;
entries++;
}
cout<< "Total "<< entries<< " events input!"<< endl;
fp.close();
}
Here are the test results:
ROOT6.13.02: It costs only 3 or 4 seconds to read in one million lines
------------------------------------------------------------
| Welcome to ROOT 6.13/02 http://root.cern.ch |
| (c) 1995-2017, The ROOT Team |
| Built for macosx64 |
| From tag v6-13-02, 20 March 2018 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------
root [0] .x csvfileGetline.cpp
******** 0 Currenttime: 2018-06-21 13:28:53 ********
******** 1000000 Currenttime: 2018-06-21 13:28:57 ********
******** 2000000 Currenttime: 2018-06-21 13:29:01 ********
******** 3000000 Currenttime: 2018-06-21 13:29:04 ********
******** 4000000 Currenttime: 2018-06-21 13:29:08 ********
******** 5000000 Currenttime: 2018-06-21 13:29:12 ********
******** 6000000 Currenttime: 2018-06-21 13:29:15 ********
******** 7000000 Currenttime: 2018-06-21 13:29:19 ********
******** 8000000 Currenttime: 2018-06-21 13:29:22 ********
******** 9000000 Currenttime: 2018-06-21 13:29:26 ********
******** 10000000 Currenttime: 2018-06-21 13:29:30 ********
******** 11000000 Currenttime: 2018-06-21 13:29:33 ********
******** 12000000 Currenttime: 2018-06-21 13:29:37 ********
ROOT6.14.00: It costs more than 2 minutes to read in one million lines
------------------------------------------------------------
| Welcome to ROOT 6.14/00 http://root.cern.ch |
| (c) 1995-2018, The ROOT Team |
| Built for macosx64 |
| From tag v6-14-00, 13 June 2018 |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------
root [0] .x csvfileGetline.cpp
******** 0 Currenttime: 2018-06-21 13:36:35 ********
******** 1000000 Currenttime: 2018-06-21 13:39:00 ********
******** 2000000 Currenttime: 2018-06-21 13:41:23 ********
******** 3000000 Currenttime: 2018-06-21 13:43:41 ********
******** 4000000 Currenttime: 2018-06-21 13:45:59 ********
******** 5000000 Currenttime: 2018-06-21 13:48:22 ********
******** 6000000 Currenttime: 2018-06-21 13:50:45 ********
******** 7000000 Currenttime: 2018-06-21 13:53:12 ********
******** 8000000 Currenttime: 2018-06-21 13:55:32 ********
******** 9000000 Currenttime: 2018-06-21 13:57:51 ********
******** 10000000 Currenttime: 2018-06-21 14:00:13 ********
******** 11000000 Currenttime: 2018-06-21 14:02:35 ********
******** 12000000 Currenttime: 2018-06-21 14:04:56 ********
For both root6.14 and root6.13.02, I have downloaded the source codes and compile them on my desktop by adding â-Dgnuinstall=ON -Dcxx17=ONâ keeping the others default which gave the informations:
â Compiler Flags: -Wc++11-narrowing -Wsign-compare -Wsometimes-uninitialized -Wconditional-uninitialized -Wheader-guard -Warray-bounds -Wcomment -Wtautological-compare -Wstrncat-size -Wloop-analysis -Wbool-conversion -m64 -pipe -W -Wshadow -Wall -Woverloaded-virtual -fsigned-char -fno-common -Qunused-arguments -pthread -std=c++1z -stdlib=libc++ -DR__HAVE_CONFIG
And here is the information of my compiler:
Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I have also tested the codes by writing main() function and use âclang++ -std=c++1z -stdlib=libc++ -o readFileStream readFileStream.cppâ. It is also as fast as root6.13.02. So, I wonder if there are internal changes on root6.14.00 to make the getline() slow? Please let me know if anyone needs more information to debug the issue. Thanks!
Thank you for your suggestion! 
