Esempio n. 1
0
 public void AddPerson(Person person)
 {
     persons.Add(person);
 }
Esempio n. 2
0
 public void AddPerson_D(string key,Person person)
 {
     persons_d.Add(key, person);
 }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Person person = new Person();
            Persons persons = new Persons();
            Random rand = new Random();
            Stopwatch sw = new Stopwatch();
            string sName;
            int found = 0;

            Console.WriteLine("Creating collection: ");

            sw.Start();
            for (int l = 0; l < 10000; l++)
            {
                sName = null;
                for (int i = 0; i < 4; i++)
                {
                    char c = (char)rand.Next(65, 91);
                    sName = sName + c;
                }
                person.Name = sName;
                sName = null;
                for (int i = 0; i < 10; i++)
                {
                    char c = (char)rand.Next(65, 91);
                    sName = sName + c;
                }
                person.SurName = sName;
                persons.AddPerson(person);
                person = new Person();
            }
            sw.Stop();

            Console.WriteLine(" -Elapsed time: {0}ms\n -Amount of persons: {1}", sw.ElapsedMilliseconds, persons.ListSize());
            Console.WriteLine("\nSearching for persons using random firstnames: ");
            sw.Restart();
            for (int l = 0; l < 1000; l++)
            {
                sName = null;
                for (int i = 0; i < 4; i++)
                {
                    char c = (char)rand.Next(65, 91);
                    sName = sName + c;
                }
                person = persons.FindPerson(sName);
                if (person != null)
                {
                    Console.WriteLine(" -Found person with {0}: {1}", sName, person);
                    found++;

                }
                else continue;
            }
            sw.Stop();

            Console.WriteLine("\nSearch results: \n -Number of results: {0} of 1000\n -Elapsed time: {1}ms", found, sw.ElapsedMilliseconds);
            persons.EraseList();

            Console.WriteLine("\nCreating dictionary: ");
            person = new Person();
            int[] s = new int[4] { 65, 65, 65, 65 };

            sw.Restart();
            for (int l = 0; l < 10000; l++)
            {
                sName = null;
                for (int i = 0; i < 4; i++)
                {
                    sName = sName + (char)s[i];
                }
                if (s[0] <= 90)
                {
                    s[0]++;
                    if (s[0] > 90)
                    {
                        s[1]++;
                        s[0] = 65;
                        if (s[1] > 90)
                        {
                            s[2]++;
                            s[1] = 65;
                            if (s[2] > 90)
                            {
                                s[3]++;
                                s[2] = 65;
                                if (s[3] > 90)
                                {
                                    s[3] = 65;
                                }
                            }
                        }
                    }
                }
                person.Name = sName;
                sName = null;
                for (int i = 0; i < 10; i++)
                {
                    char c = (char)rand.Next(65, 91);
                    sName = sName + c;
                }
                person.SurName = sName;

                persons.AddPerson_D(person.Name, person);
                person = new Person();
            }
            sw.Stop();
            found = 0;

            Console.WriteLine(" -Elapsed time: {0}ms\n -Amount of persons: {1}", sw.ElapsedMilliseconds, persons.ListSize_D());
            Console.WriteLine("\nSearching for persons using random firstnames: ");

            sw.Restart();
            for (int l = 0; l < 1000; l++)
            {
                sName = null;
                for (int i = 0; i < 4; i++)
                {
                    char c = (char)rand.Next(65, 91);
                    sName = sName + c;
                }
                person = persons.FindPerson_d(sName);
                if (person != null)
                {
                    Console.WriteLine(" -Found person with {0}: {1}", sName, person);
                    found++;

                }
                else continue;
            }
            sw.Stop();

            Console.WriteLine("\nSearch results: \n -Number of results: {0} of 1000\n -Elapsed time: {1}ms", found, sw.ElapsedMilliseconds);
            Console.Read();
        }