Accroding to the QFileInfo
documentation:
Some of
QFileInfo
's functions query the file system, but for performance reasons, some functions only operate on the file name itself.
However, I'm still not sure which methods do access the file itself under the hood and which don't. For example:
for (int i = 0; i < 100000; ++i) {
QFileInfo fi("path/to/my/file");
qDebug() << fi.fileName();
}
Does this code has penalty over the following?
for (int i = 0; i < 100000; ++i) {
QString fileName = QString("path/to/my/file").split('/').last();
qDebug() << fileName;
}
Because I'm not sure which QFileInfo
methods (or even constructor) access the file itself.
Of course, I can do some profiling, and probably it would be a premature optimization in terms of the code speed, however I'm worried about the HDD. I know about the QFileInfo
caching, so imagine that I will try to get the filename of different files.