file check
Chris Jack
chris_jack at msn.com
Tue Jul 15 15:56:33 BST 2008
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
% echo hi>> z2
% time cmp -s z z2
real 0m0.024s
user 0m0.003s
sys 0m0.009s
% time cksum z
1620340937 634827102 z
real 0m6.287s
user 0m4.996s
sys 0m1.152s
Chris
_________________________________________________________________
Invite your Facebook friends to chat on Messenger
http://clk.atdmt.com/UKM/go/101719649/direct/01/
More information about the london.pm
mailing list