How to compare two files quickly?
-
I just want to know if the two binary files is same. if i compare them byte by byte , it'll cost a lot of time. is there some good method?
No, this is the fastest way. The speed will depend on realization. while (*p1++==*p2++); will be slower than memcmp, fully loaded files are a bit faster then mapped files, etc. The only alternative is some crc generation, but it will be faster only when comparing one file to many. Igor Green http://www.grigsoft.com Compare It! + Synchronize It! : Files and folders comparison never was easier!
-
I just want to know if the two binary files is same. if i compare them byte by byte , it'll cost a lot of time. is there some good method?
BAsicly yes. If you want some example source code, search for "diff", which is a unix utility that does what you want. (and many other things)
-
I just want to know if the two binary files is same. if i compare them byte by byte , it'll cost a lot of time. is there some good method?
A simple check on length would be a quick way to say they are different. Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain) -
BAsicly yes. If you want some example source code, search for "diff", which is a unix utility that does what you want. (and many other things)
Henry miller wrote: If you want some example source code, search for "diff", which is a unix utility that does what you want. (and many other things) Good idea. However, "diff" is for text files. If you want to compare binary files, try the unix utility "cmp" If you don't have the source to the unix utilities, try looking at cygwin, a Unix-on-DOS implementation: http://www.cygwin.com[^]