As noted in the comments, byte-by-byte comparison will be the fastest (if all the bytes are in memory, of course - however, in C # the opposite must be realized).
But for a start, files can simply be compared in size. If it is different, the files are obviously different.
If the dimensions are identical, and you still need to compare byte-bye, the files can be divided into pieces, and run the comparison in parallel mode.
I will give the code with an example of such a comparison. The code is not perfect and not universal, but you can push it off
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; namespace FileCompare { class Program { static void Main(string[] args) { //Считываем файлы в память var file1 = File.ReadAllBytes("file1.bin"); //10 000 000 байт var file2 = File.ReadAllBytes("file2.bin"); //10 000 000 байт var partsCount = 10; //количество частей var partSize = 1000000; //размер части //делим файлы на списки частей var parts1 = new List<IEnumerable<byte>>(); var parts2 = new List<IEnumerable<byte>>(); for (int i = 0; i < partsCount; i++) { var skip = i * partSize; parts1.Add(file1.Skip(skip).Take(partSize)); parts2.Add(file2.Skip(skip).Take(partSize)); } //Создаём список тасков. Метод Task.Run запускает задачу сразу после создания //Так же обратите внимание на current = i в каждой итерации. var comparsionTasks = new Task<bool>[partsCount]; for (int i = 0; i < partsCount; i++) { var current = i; comparsionTasks[current] = Task.Run(()=> { Console.WriteLine($"Running {current}..."); return parts1[current].SequenceEqual(parts2[current]); }); } //ожидаем завершения всех задач Task.WaitAll(comparsionTasks); //вывод результатов в консоль foreach (var task in comparsionTasks) Console.WriteLine(task.Result); Console.ReadKey(); } } }
By the way, keep in mind that for small files this solution will only slow down the comparison. Here only to measure.
And one more thing : you can use CancellationToken to stop the comparison as soon as different bytes are detected.