Basic machine operations such as XOR, SUB, CMP, TEST are all simple enough so they all operate extremely fast. They also set the same condition code bits. From the point of view of compare-for-equal, these all set the Z bit the same way; other bits are set differently because these operations compute different results.
For the x86 CPUs, there is no difference in execution times of these, because they all use identical pathways through the chip. Consequently you can use any of them without performance penalty where it computes the answer that you want. (Technically a SUB should take longer than XOR because the carry has to "ripple" through all the bits, whereas XOR is bit-by-bit parallel. The CPU designers have figured out ways to build extremely fast carry-computing logic so the effective time difference isn't significant. They have huge motivation to do so, since most of what a computer does is "add"]).
As a style convention, if you think you are "comparing two (machine-word-sized) values", you should probably use the CMP instruction, because that communicates what you are thinking to the reader of your code. And it has the advantage that it doesn't destroy one of the operands, which you will find ultimately a very persuasive argument for using it instead of XOR, once you've written enough code. (TEST has this nice property, useful for checking bits, too).
There are compares of other kinds of values for which other x86 instructions are better: floating compares, string compares, vector register compares, etc. These instructions take different times than the basic operations because they must do more complicated things (like comparing multiple data words).