Details
-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
4.7.1
-
None
-
OS X
Description
#include <QFile> #include <QDebug> #include <QStringList> #include <QCoreApplication> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QStringList args = a.arguments(); if( 2 != args.size()) { qDebug() << "Usage: " << args[0] << "FileName"; return -1; } QFile file( args[1] ); if ( ! file.open(QIODevice::ReadOnly ) ) { qDebug() << "cound not open file " << args[1]; return -1; } while ( ! file.atEnd() ) { char c; #if 1 file.getChar(&c); #else QByteArray data = file.read( 4096 ); for(int i = 0 ; i < data.size() ; ++i ) { c = data.at(i); } #endif } return 1; }
changing "#if 1" to "#if 0" the code runs 25x faster:
(Tested using an ~800Mb file)
real 0m18.907s
user 0m17.832s
sys 0m0.514s
vs
real 0m0.744s
user 0m0.180s
sys 0m0.454s
I would expect this behavior, except the documents contradict. From QIODevice doc:
"Some subclasses, such as QFile and QTcpSocket, are implemented using a memory buffer for intermediate storing of data. This reduces the number of required device accessing calls, which are often very slow. Buffering makes functions like getChar() and putChar() fast, as they can operate on the memory buffer instead of directly on the device itself."
I only tested on OSX