QFile is looking for performance

It seems that the QFile when working with a regular file (and not a special Linux I / O device file) is random access, which means the search operation has O (1) constant complexity.

However, I could not confirm this. In general, when moving to a specific position in a file (for writing or reading) do std::fstream and QFile provide continuous time complexity?

+2
source share
1 answer

The short answer is yes, for practical purposes. The long answer ... It's complicated.

Finding the file stream ultimately calls lseek () in the base file descriptor, the performance of which depends on the kernel.

The uptime depends on which file system you are using and how large the files are. As files grow larger, random queries require the pursuit of more β€œindirect” indexing blocks. But even for files up to 2 ^ 64 bytes in size, the number of levels is only a few.

So, in theory, the search is probably O (log n); but in practice it is essentially constant for a modern file system.

+3
source

All Articles