I already found some posts relating to Qt and writing a file with C++, but I didn't find a comparison of existing methods and a satisfying answer to the question "What's the fastest method writing a file in Qt?"...
The task: I need to write a whole bunch of double values (around 500.000 up to 1.000.000) to file to a file. Due to my program structure, this values are saved in a QList, which contains some QVectors (every QVector has same size). The QVectors contains the double values. Additionally, each column (each QList element is a column) has to be written with different precision. Each column is seperated with a \\t.
I tried several methods:
In the end I got the best results with QTextStream and FILE using fwrite (nearly same speed), QFile with the QFile::write was a little bit slower (maybe 30%).
But I still think that there must be a faster method. For 500.000 double values my PC (Core2Duo) needs about 2s, and that's quite very long.
I also thought about using the Boost Karma C++ Library - can you recommend it? http://www.boost.org/doc/libs/1_51_0/libs/spirit/doc/html/spirit/karma.html
Assuming you are doing it like below, it is unlikely you will find anything faster than fwrite.
double values[1000] = {...};
fwrite(values, sizeof(double), 1000, f);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.