[comp.unix.wizards] cmp efficiency

nick@ccicpg.UUCP (Nick Crossley) (06/23/88)

> While we're on the subject of efficiency, cmp is coded wrong. It should
> first stat the two files to be compared. If the character count is different,
> so are the files. And files tend to be different more often than the same.

First, files given to cmp are quite likely to be the same, in my experience.

Second, if the files are not the same size, cmp will tell you if they have the
same contents up to the length of the shorter (cmp will say 'EOF on file 1/2').
I find this useful in some contexts, and would not want cmp just to give up
if the sizes differed.
-- 

<<< standard disclaimers >>>
Nick Crossley, CCI, 9801 Muirlands, Irvine, CA 92718-2521, USA
Tel. (714) 458-7282,  uucp: ...!uunet!ccicpg!nick

aledm@cvaxa.sussex.ac.uk (Aled Morris) (07/08/88)

In article <3048@ccicpg.UUCP>, nick@ccicpg.UUCP (Nick Crossley) writes:
>>While we're on the subject of efficiency, cmp is coded wrong. It should
>>first stat the two files to be compared. If the character count is different,
>>so are the files. And files tend to be different more often than the same.
[...]
>        if the files are not the same size, cmp will tell you if they have the
>same contents up to the length of the shorter (cmp will say 'EOF on file 1/2').
>I find this useful in some contexts, and would not want cmp just to give up
>if the sizes differed.

I never use "cmp" and to read its output, I only ever use it with "-s".
If you specify this flag, cmp really ought to look at the file sizes first.

Aled Morris
systems programmer

      mail: aledm@uk.ac.sussex.cvaxa   |   School of Cognitive Science
      uucp: ..!mcvax!ukc!cvaxa!aledm   |   University of Sussex
      talk: +44-(0)273-606755  x4284   |   Falmer, Brighton  BN1 9QN
       fax: +44-(0)273-678335          |   East Sussex, England
   "I'm living in the future/I feel wonderful/I'm tipping over backwards...
I'm so ambitious/I'm looking back/I'm running a race and you're the book I read"