Saturday, 15 January 2011

algorithm - C fastest way to compare two bitmaps -


There are two arrays of bitmap in the form of four arrays with millions of records, the fastest way to compare them using C what might happen.

I can imagine using a bitwise operator xor 1 byte for loop at a time.

Important point about bitmap:

  • 1% to 10% algorithm is run, bitmaps may be different most of the time they are similar. When they can be different, they can do as much as 100%
  • Both bitmaps are of the same length.

    Purpose:

    • Check if they are different, and if so, where?
    • Be correct every time (the probability of detecting the error should be 1).

      This answer assumes that 'bitmap' means' rather than 'bitmap image format' 0/1 is the sequence of values ​​

      If you are just two bitmaps of the same length and want to quickly compare them, memcmp () will be effective because Suggestions are given in the comments if you want to try using the SSE type optimization but it is not as easy as memcmp () . memcmp () assumes that you just want to know 'they are different' and nothing else.

      If you want to know how many bits they are different from, e.g. 615 bits are different, then you have a few options, except XT except by every byte and counting the number of differences. As others have mentioned, you may want to do more on 32/64 or 256 bits, depending on your platform at this time. However, if the arrays are millions of bytes long, the biggest delay (with current CPUs) will be time to move the main memory to the CPU, and it does a lot of talk about what the CPU does (many permissions) < / P>

      If you are asking more about comparing questions A to B, but in reality you are doing so many times, like A to B and C, D, etc. etc., then you have a few things You can

      • Store the checksum of the queen and compare the checksum first, if it is the same then there is a very chance that the arrays are the same, obviously there is a risk that checksum may be equal but the data can be different, so make sure That the wrong consequences in this case will not be on dramatic side effects. And, if you can not catch the wrong results, then do not use this technique.
      • If there is a structure of arrays, as if they are image data, then to answer the specific tool to take advantage of this, it is beyond the answer.
      • If image data can be effectively compressed, then shrink each array and compare using Compressed Form. If you use compression of the zip type, you can not tell how many bits separately from the zip, but other techniques like RLE can be effective for counting bit differences faster (but a lot of work is accurate and fast To create and receive) >
      • d. If acceptable with the risk of (A), you can check each section of 262144 bits, and only calculate the difference where checksum is different. It greatly reduces memory access and is very fast.

        All options A ... D is about reducing main memory access because it is the name of any performance gain (called for problem)

No comments:

Post a Comment