private bool FindInListVSDictionaryHandMadeHash(int count) { Dictionary <PersonHandMadeHash, string> dictOfPerson = GeneratePersonsDictionaryWithHandMadeHash(count); List <PersonHandMadeHash> listOfPeorson = GeneratePersonsListWithHandMadeHash(count); Dictionary <PersonHandMadeHash, string> .KeyCollection keys = dictOfPerson.Keys; PersonHandMadeHash[] keysPerson = new PersonHandMadeHash[keys.Count]; keys.CopyTo(keysPerson, 0); PersonHandMadeHash person = keysPerson[_rand.Next(0, keys.Count)]; FindInDictionary(dictOfPerson, person); Console.WriteLine("На поиск элемента в словаре с " + count + " элементов с const хешем ушло : " + stopwatch.ElapsedMilliseconds + " миллисекунд"); long stopwatchTime = stopwatch.ElapsedMilliseconds; FindInList(person, listOfPeorson); Console.WriteLine("На поиск элемента в cписке с " + count + " элементов с const хешем ушло : " + stopwatch.ElapsedMilliseconds + " миллисекунд"); if (stopwatch.ElapsedMilliseconds > stopwatchTime) { return(true); } else { return(false); } }
private bool FindInList(PersonHandMadeHash person, List <PersonHandMadeHash> list) { stopwatch.Restart(); bool result = list.Contains(person); stopwatch.Stop(); return(result); }
private bool FindInDictionary(Dictionary <PersonHandMadeHash, string> dictionary, PersonHandMadeHash person) { stopwatch.Restart(); bool result = dictionary.ContainsKey(person); stopwatch.Stop(); return(result); }