DEV Community

Discussion on: How to compare two files using .NET, really really fast!

Collapse
 
manuc66 profile image
Emmanuel Counasse

Be carefull the algorithm ReadFileInChunksAndCompareAvx2 is not correct you must move into oh1 and oh2 otherwise you are always comparing the same segment.

I would fix the last loop with :

var totalProcessed = 0;
while (totalProcessed < count1) {
    var result = Avx2.CompareEqual(Avx.LoadVector256(oh1+ totalProcessed), Avx.LoadVector256(oh2+totalProcessed));
    if (Avx2.MoveMask(result) != -1) {
        return false;
    }
    totalProcessed += Vector256<byte>.Count;
}
Enter fullscreen mode Exit fullscreen mode