コード例 #1
0
ファイル: Program.cs プロジェクト: yuliapetrova/CSharpTasks
        public static void CalculateTime(Queue stack, int k)
        {
            // Add
            var startAdding = DateTime.Now;
            string test = "Test string";
            for (int i = 0; i < k; i++)
            {
                stack.Enqueue(test);
            }
            var finishAdding = DateTime.Now;
            Console.WriteLine("Addition time (" + k + " elements) : " + stack.GetType() + "  " + (finishAdding - startAdding));

            // Search
            var startSearch = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                bool a = stack.Equals(test);
            }
            var finishSearch = DateTime.Now;
            Console.WriteLine("Search time (" + k + " elements) : " + stack.GetType() + "  " + (finishSearch - startSearch));

            // Remove
            k = 1000000;
            var startRemoving = DateTime.Now;
            for (int i = 0; i < k; i++)
            {
                stack.Dequeue();
            }
            var finishRemoving = DateTime.Now;
            Console.WriteLine("Removal time (" + k + " elements) : " + stack.GetType() + "  " + (finishRemoving - startRemoving) + "\n");
        }