Agreed. You can make it a lot more efficient by
ing all the files and only bothering to compare the contents of those which are the same size. Another small improvement can come from noting that those with the same device number and inode number are guaranteed to be the same so no need to compare their contents, although this may not be portable to non-Unixy platforms.
You should also be careful about how you compare symlinks and device files.