Usenet comp.unix.tru64 (2000-2013)
 help / color / mirror / Atom feed
* reading a file slooooooow with c++ getline
@ 2001-02-20 12:28 Alexandre Masselot
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Masselot @ 2001-02-20 12:28 UTC (permalink / raw)


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 <fstream>
#include <iostream>
#include <string>

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 <stdio.h>

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


^ permalink raw reply	[flat|nested] 2+ messages in thread
* reading a file slooooooow with c++ getline
@ 2001-02-20 12:02 Alexandre Masselot
  0 siblings, 0 replies; 2+ messages in thread
From: Alexandre Masselot @ 2001-02-20 12:02 UTC (permalink / raw)


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 <fstream>
#include <iostream>
#include <string>

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 <stdio.h>

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-02-20 12:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-02-20 12:28 reading a file slooooooow with c++ getline Alexandre Masselot
  -- strict thread matches above, loose matches on Subject: below --
2001-02-20 12:02 Alexandre Masselot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox