The verb compare can be used with both the preposition to and the preposition with, but the notion of the comparison is different.
Compare to is used to stress similarity, whereas Compare with stresses the difference.
(1) We compare our results to X’s results.
(2) We compare our results with X’s results.
In (1), we may expect that X achieved similar results, while in (2) X’s results are probably significantly better/worse. Another example in one sentence:
In summary, we achieved the same accuracy, compared to X, but comparing our running time with X’s algorithm, our algorithm.
To remember when to use which preposition, think of the following example; being similar takes a to – not a with:
Our results are similar to X’s results.
-  More details Daily Writing Tips