Using Python 2.7, I checked some "tests"
outfile.write(infile.read())
vs
shutil.copyfileobj(readfile, outfile)
I repeated over 20 .txt files ranging in size from 63 MB to 313 MB with a total file size of ~ 2.6 GB. In both methods, normal read mode performed better than binary read mode, and shutil.copyfileobj was usually faster than outfile.write.
When comparing the worst combination (outfile.write, binary mode) with the best combination (shutil.copyfileobj, normal reading mode), the difference was quite significant:
outfile.write, binary mode: 43 seconds, on average. shutil.copyfileobj, normal mode: 27 seconds, on average.
The original file had a final size of 2620 MB in normal read mode and 2578 MB in binary read mode.
source share