Here's some Python code (using OpenCV & numpy) that is roughly equivalent to OP's imgdiff. It is single-threaded but it'll be vectorised and it's 3x faster on my 5-year-old 2-core laptop (even counting the Python overhead):
import sys, cv2, numpy
f1 = cv2.imread(sys.argv[1])
f1 = cv2.cvtColor(f1, cv2.COLOR_BGR2GRAY)
f2 = cv2.imread(sys.argv[2])
f2 = cv2.cvtColor(f2, cv2.COLOR_BGR2GRAY)
threshold = 0.1
absdiff = cv2.absdiff(f1, f2)
_, thresholded = cv2.threshold(
absdiff, int(threshold * 255),
255, cv2.THRESH_BINARY)
cv2.imwrite("output.png", thresholded)
print("Different pixels: %s" % numpy.count_nonzero(thresholded))
Benchmark: $ /usr/bin/time python test.py water-4k.png water-4k-2.png
Different pixels: 89153
1.39user 0.34system 0:01.33elapsed 129%CPU
$ /usr/bin/time ./imgdiff water-4k.png water-4k-2.png output.png
Failure! Images are different.
Different pixels: 89142
Command exited with non-zero status 1
8.85user 0.10system 0:04.02elapsed 222%CPU
(Edit: The Python code is a simplified version extracted from https://github.com/stb-tester/stb-tester -- we use it for regression testing of GUI screenshots.)