Dagfinn Ilmari Mannsåker
ilmari at ilmari.org
Tue Jul 15 16:16:24 BST 2008
Chris Jack <chris_jack at msn.com> writes:
> Aaron Crane writes:
>> Chris Jack writes:
>>> cmp doesn't seem smart enough to check file size first.
>> cmp's default mode of operation involves emitting a description of the
>> first difference -- either a byte/line position or an "EOF on $file"
>> message. That can't be done without examining the whole of both
>> files, even if they're of different sizes.
>> But the -s option will switch cmp into a mode where it reports
>> equality using nothing but its exit status; at that point, cmp (or at
>> least the version I've just tried with, from GNU diffutils 2.8.1) will
>> return instantly if the files are of different sizes.
> You're right! And "-s" runs much faster even on equal files, but not
> nearly as fast as unequal ones.
> % time cmp z z2
> real 0m7.970s
> user 0m6.132s
> sys 0m1.642s
> % time cmp -s z z2
> real 0m2.369s
> user 0m0.667s
> sys 0m1.632s
I'm guessing this is due to using memcmp(), which compares word-wise if
it can, instead of comparing byte-wise, since it doesn't need to tell
_which_ byte it differs at.
"A disappointingly low fraction of the human race is,
at any given time, on fire." - Stig Sandbeck Mathisen
More information about the london.pm