I just ran some benchmarks on a 100+ MB file. diff was the fastest, while cmp came second, and using md5sum came in last.
# time diff file1 file2; echo $?
real 0m0.122s
user 0m0.009s
sys 0m0.113s
0
# time cmp file1 file2; echo $?
real 0m0.213s
user 0m0.097s
sys 0m0.117s
0
# time md5sum file1 > /tmp/test; time md5sum file2 > /tmp/test2; diff /tmp/test /tmp/test2; echo $?
real 0m0.279s
user 0m0.211s
sys 0m0.066s
real 0m0.316s
user 0m0.225s
sys 0m0.073s
0
I reran the exercise with a 4.3 GB file, and had to delete and recreate the file with dd since RAM caching was greatly affecting the results.
$time diff file1 file2; echo $?
real 0m19.325s
user 0m0.995s
sys 0m5.280s
0
$time cmp file1 file2; echo $?
real 0m36.106s
user 0m4.399s
sys 0m6.147s
0
$time md5sum file1 > /tmp/test; time md5sum file2 > /tmp/test2; diff /tmp/test /tmp/test2; echo $?
real 0m10.441s
user 0m8.054s
sys 0m2.357s
real 0m24.682s
user 0m8.027s
sys 0m3.442s
0
Based on these results I would recommend moving the files to a RAMFS mount, and sticking with diff.