I have a bunch of images to download, after their downloaded I'd like to check them against one "special" image to see if the开发者_高级运维re exactly the same as this image. To do this I could just compare the arrays directly item by item or I could compute a hash and compare this.
I think in this case directly comparing will be quicker, as we only do one comparison, so the cost of hashing will be greater than saving of time spent on comparison. However, I'm not sure this reasoning is sound (which is why I'm asking). I can see that hashing comes into its own if you're doing multiple comparisons for each image but in this case I'm not.
Admittedly I could just implement both solutions and benchmark (but it's fun asking so questions).
Yep, just comparing the images pixel by pixel should be faster. But in boundary cases it may depends on the size of your image (and other contextual parameters) - for example, if your images are very large, you are better off computing a hash, cause memory accessing costs will start to peak.
精彩评论