Esempio n. 1
0
        public static double computeHashTableAddAndSearchTime(int input)
        {
            Stopwatch stopwatch = new Stopwatch();

            // Hash Table performance Tests
            task1.HashTableImpl <string, string> hastable = new task1.HashTableImpl <string, string>(input);
            // Begin timing.
            ArrayList list = Utility.getRandomStringList(input);

            for (int i = 0; i < list.Count; i++)
            {
                Console.WriteLine("Adding value to hashtable - " + list[i]);
                //string random = RandomString(5);
                hastable.Add(list[i] + "-Key", list[i] + "-Value");
            }
            Console.WriteLine("Time takeen to Add {0} items. Time elapsed: {1:hh\\:mm\\:ss}", input, stopwatch.Elapsed);

            // Get time for GET function
            stopwatch.Start();
            for (int i = 0; i < list.Count; i++)
            {
                string key = list[i] + "-Key";
                // Console.WriteLine("Query value from hashtable - " + list[i]);
                //string random = RandomString(5);
                string value = hastable.Search(key);
                Console.WriteLine("Value found for key = {0}  Value = {1}", key, value);
            }
            //System.Threading.Thread.Sleep(1000);
            // Stop timing.
            stopwatch.Stop();
            double timeInMillis = stopwatch.ElapsedMilliseconds;

            Console.WriteLine("Time takeen to GET {0} items. Time elapsed: {1} ms", list.Count, timeInMillis);
            return(timeInMillis);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            int input = 200;

            task1.HashTableImpl <string, string> hastable = new task1.HashTableImpl <string, string>(input);
            for (int i = 0; i < input; i++)
            {
                string random = RandomString(5);
                hastable.Add(random + "-Key", random + "-Value");
            }
        }