Given the above information, I would say that mmap is a good candidate. Here are a few reasons why I say: 1. It gives you a WHOLE file without actually downloading (any) file until this part is needed. This is an advantage for fast loading, but if you end up going through each byte (or touch each section of the 4KB file), then there is not much difference. 2. mmap will only copy ONCE data from disk to your pages. This is more efficient in my testing than reading using fread or read on Linux (note also that the difference between fread and read for large reads can be ignored. In functions in C. C ++ streams, to add a fair bit of overhead costs, however, in my experience [I have tried many times various forms of this time].
As always, benchmarking always trumps the Internet. So you CAN FIND that what I said above is not appropriate for your circumstances. And, as indicated, if the code is good enough, any overhead in the code overshadows the speed at which drives can deliver data, even if you have a very fantastic RAID system with lots of parallel (SSD?) Drives, etc., in the end As a result, the transfer speed of the disk will be where the bottleneck is. All you can do at this moment is to try as little as possible other overhead costs, and get the data into the application as quickly as possible after the disk has delivered the data.
A good reference for bytes per second is to use dd if=/dev/zero of=somefile bs=4K count=1M (which writes the file, then you might want dd if=somefile of=/dev/null bs=4K to see how well you can read from disk.
Mats petersson
source share