A 2 GB file is quite large, and you need to know all the possible areas that can act as bottlenecks:
- Hard drive itself
- Hard Drive Interface (IDE / SATA / RAID / USB?)
- Operating system / file system
- C / C ++ Library
- Your code
I would start with some measurements:
Assuming your drive is capable of reading / writing at a speed of around 40 Mbps (which is probably a realistic figure to start with), your 2 GB file cannot run faster than about 50 seconds.
How long has this been going on?
Hi Roddy, using the fstream read method with 1.1 GB files and large buffers (128 255 or 512 MB) takes about 43-48 seconds, and it's the same with fstream getline (line by line). cp takes about 2 minutes to copy the file.
In this case, your hardware binding. cp has to read and write, and will look back and forth across the surface of the disk, like crazy when it does. Thus, it will (as you see) be more than twice worse than a simple โreadโ case.
To increase speed, the first thing I will try is a faster hard drive or SSD.
You did not say what is the interface on the disk? SATA is the easiest and fastest option. Also (obviously, this ...) make sure that the disk is physically located on the same computer that your code is running on, otherwise you are tied to the network ...
Roddy
source share