public void FindSubstringPerformance() { var bigString = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç."; var smallString = "34567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmö"; var stopWatch1 = Stopwatch.StartNew(); stopWatch1.Start(); for (int i = 0; i < 100000; i++) { RabinKarp.FindSubstring(bigString, smallString); } stopWatch1.Stop(); var time1 = stopWatch1.ElapsedMilliseconds; var stopWatch2 = Stopwatch.StartNew(); stopWatch2.Start(); for (int i = 0; i < 100000; i++) { bigString.IndexOf(smallString); } stopWatch2.Stop(); var time2 = stopWatch2.ElapsedMilliseconds; Assert.IsTrue(time1 < time2); }
public void FindSubstring() { var bigString = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç."; var smallString = "klşi"; var pos = RabinKarp.FindSubstring(bigString, smallString); var posToCheck = bigString.IndexOf(smallString); Assert.AreEqual(pos, posToCheck); bigString = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç."; smallString = "XYZ"; pos = RabinKarp.FindSubstring(bigString, smallString); posToCheck = bigString.IndexOf(smallString); Assert.AreEqual(pos, posToCheck); bigString = "1234567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmöç."; smallString = "34567890*-qwertyuıopğüasdfghjklşi,<zxcvbnmö"; pos = RabinKarp.FindSubstring(bigString, smallString); posToCheck = bigString.IndexOf(smallString); Assert.AreEqual(pos, posToCheck); }