From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fa528,e8460df81e913ac3 X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2001-02-20 04:29:29 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.tele.dk!4.1.16.34!cpk-news-hub1.bbnplanet.com!news.gtei.net!feed2.news.rcn.net!rcn!wn4feed!worldnet.att.net!164.128.36.58!newsfeed-zh.ip-plus.net!not-for-mail From: Alexandre Masselot Newsgroups: comp.unix.tru64 Subject: reading a file slooooooow with c++ getline Date: Tue, 20 Feb 2001 13:28:54 +0100 Organization: Swisscom IP+ (post doesn't reflect views of Swisscom) Message-ID: <3A926306.DC122878@geneprot.com> NNTP-Posting-Host: 194.209.13.177 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: rex.ip-plus.net 982672161 23129 194.209.13.177 (20 Feb 2001 12:29:21 GMT) X-Complaints-To: abuse@ip-plus.net NNTP-Posting-Date: Tue, 20 Feb 2001 12:29:21 +0000 (UTC) X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.14-5.0 i686) X-Accept-Language: en Xref: supernews.google.com comp.unix.tru64:1744 Comparing reading times on an es/40 with two techinques gives me dramatic timings. The c++ (compiled with cxx) version with getline(ifstream,is) is 50 times slower than the c version with fgets. The c++ version is even 6 times slower on a es/40 than on my pc with g++ Ok, reading on a string can be a bit slower than directly to a char buffer, but a factor 50 slower??? I'm rather new to c++, so I may miss a big issue. And i feel rather comfortable to manipulate strings in this case. thanks for your help Alex ps below c++ and c version, code and timing /tmp/a.txt is a simple text file (~10M) The c++ alex@gm-mastdev:misc>cxx -V Compaq C++ V6.3-002 for Compaq Tru64 UNIX V5.1 (Rev. 732) Compiler Driver V6.3-002 (cxx) cxx Driver #include #include #include int main(){ ifstream is("/tmp/a.txt"); string s; while(!is.eof()){ getline(is,s); } is.close(); return 0; } alex@gm-mastdev:misc>!cxx cxx -O4 read.cpp -o read-cpp alex@gm-mastdev:misc>time ./read-cpp real 0m16.637s user 0m16.347s sys 0m0.146s the C version alex@gm-mastdev:misc>cc -V Compaq C V6.3-027 on Compaq Tru64 UNIX V5.1 (Rev. 732) Compiler Driver V6.3-026 (sys) cc Driver #include int main(int argc, char *argv){ int BlockSize=8; FILE *pf1; char BUF[32*1024+1]; int i,S=1024*BlockSize; pf1=fopen("/tmp/a.txt","r"); fgets(BUF,S,pf1); while(!feof(pf1)){ fgets(BUF,S,pf1); } fclose(pf1); exit (0); } cc -O4 read.c -o read-c alex@gm-mastdev:misc>time ./read-c real 0m0.357s user 0m0.043s sys 0m0.064s