How are you?
I'm writing a computer program (using C++/Qt) that is supposed to analyze data faster than another program. I wrote a simple script that does nothing more than just reads the data (doesn't store it anywhere) and my script is 5% slower than the other program together with analysis. This is a complete mystery to me. It appears that there must be super fast ways to read in data that I don't know of. The input file (data) is a text file containing a space-delimited table about 1 thousand by 1 million entries. The first 5 columns are sting and the others are double.
Do you see anything weird in my code? How could text be read any faster?

My code is here:
QFile Gfile("input.txt"); if(!Gfile.open(QIODevice::ReadOnly | QIODevice::Text)) {exit(1);}
QTextStream G_stream(&Gfile);

QString readString, RSnumber; double readFloat;

while(!G_stream.atEnd())//G loop

  G_stream >> readString;
  if(G_stream.atEnd()) {break;}

  G_stream >> readString; RSnumber=readString;//RSnumber is stored, other strings not stored
  G_stream >> readString; G_stream >> readString; G_stream >> readString;

         for(k=5; k<Glength-2; k=k+3)//Glength given by user
         G_stream >> readFloat;//parameter1
         G_stream >> readFloat;//parameter2
         G_stream >> readFloat;//parameter3

Or maybe I should use simple C to gain speed??

Thanks a lot,

> Or maybe I should use simple C to gain speed??

I've no idea about Qt input/output performance.

It is quite possible that C input/output is faster than standard C++ streams on your implementation.

There is an interesting discussion on input/output performance here:
You may find it interesting.


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2016 About.com. All rights reserved.