|
|
Lines 14/15, you call the default constructor for char, which sets all the chars to 0. It's completely useless and takes time for nothing. |
|
|
You could use a buffer bigger than 1MB. |
|
|
gcc(linux) 0.92 s intel(linux) 0.97 s sun(sun) 4.04 s xlc(ibm) 3.67 s |
gcc 1.80 s intel 1.89 s sun(sun) 14.5 s xlc(ibm) 2.43 s |
|
|
gcc(linux): 14.1 s intel(linux): 35.2 s sun(sun) 29.3 s xlc(ibm) 27.1 s |
just for fun, I ran this on a few boxes. On Linux, I was comparing two copies of Intel parallel studio distro (size 2,152,945,149 bytes), on Sun and IBM, two copies of some binary of size 898,215,121 bytes) memory-mapped version (as posted by me) gcc(linux) 0.92 s intel(linux) 0.97 s sun(sun) 4.04 s xlc(ibm) 3.67 s ifstream.read() version into a 1M buffer (as posted by seftoner) gcc 1.80 s intel 1.89 s sun(sun) 14.5 s xlc(ibm) 2.43 s trivial I/O stream-based version 1 2 3 if(std::equal(std::istreambuf_iterator<char>(f1), std::istreambuf_iterator<char>(), std::istreambuf_iterator<char>(f2))) gcc(linux): 14.1 s intel(linux): 35.2 s sun(sun) 29.3 s xlc(ibm) 27.1 s |
|
|
|
|
1. Pre-compute and store a checksum (say MD5) for each large file file (along with a timestamp). 2. If the file was not modified after the timestamp, compare the checksums first. Compare byte by byte only if the checksums and the file sizes match. |