If you need to compare one-dimensional arrays of C structs , you can try memcmp() to see if this is a more efficient for loop. If you can afford some kind of hash array, you can significantly improve performance for cases where arrays are different. For example, if you have an array of floats, you can use their sum as a hash. If the hashes of arrays are different, you do not need to compare arrays at all. On the other hand, if you expect arrays to actually be equal in most cases, computing a hash will only slow things down.
Being creative with hash calculation can also help. In the case of 2D arrays, the hash can be a polynomial of the hashes of a 1D array or even a struct with metadata such as array sizes, hash hashes of 1D arrays, etc.
EDIT: on my machine, memcmp() about 2 times faster than a straightforward single-threaded for loop when comparing large arrays of floats in the worst case (when the arrays are equal).
source share