You use "compare to" when you liken something to another. For example, John compared my voice to David's voice.
"Compare with" is used when you discuss similarities and difference between two things. For example, Compare John's performance with David's and you would see that David has fared much better.
Teachers, kindly correct me as well if I have made any mistake.