Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            StringBuilder Result = new StringBuilder();
            const int TestRepeatsCount = 1000000;
            Counter counter = new Counter();
            int Key = 3;
            this.progressBar1.Value = 0;

            counter.Start();
            for (int i = 0; i < TestRepeatsCount; ++i)
                BinaryTree.Search(Key);
            counter.Stop();
            this.progressBar1.Value += 25;
            Double BTreeTime = counter.TotalSeconds;

            counter.Reset();
            counter.Start();
            for (int i = 0; i < TestRepeatsCount; ++i)
                BalancedBinaryTree.Search(Key);
            counter.Stop();
            this.progressBar1.Value += 25;
            Double BalancedBTreeTime = counter.TotalSeconds;

            Info InfoKey = new Info(Key);
            counter.Reset();
            FillOAHashTable(ref OATable);
            counter.Start();
            for (int i = 0; i < TestRepeatsCount; ++i)
                OATable.Search(InfoKey);
            counter.Stop();
            this.progressBar1.Value += 25;
            Double OATableTime = counter.TotalSeconds;


            counter.Reset();
            FillCAHashTable(ref CATable);
            counter.Start();
            for (int i = 0; i < TestRepeatsCount; ++i)
                CATable.Search(Key);
            counter.Stop();
            this.progressBar1.Value += 25;
            Double CATableTime = counter.TotalSeconds;

            Result.Append("Количество повторений = " + TestRepeatsCount.ToString() +
                ".\nБинарное дерево\n\t-Время поиска = " + BTreeTime.ToString("F2") +
                "\n\t-Занимаемая память = " + BinaryTree.getMemory() +
                " байт\nСбалансированное бинарное дерево\n\t-Время поиска = " + BalancedBTreeTime.ToString("F2") +
                "\n\t-Занимаемая память = " + BalancedBinaryTree.getMemory() +
                " байт\nХеш-таблица с открытой адресацией\n\t-Время поиска = " + OATableTime.ToString("F2") +
                "\n\t-Занимаемая память = " + OATable.getMemory() +
                " байт\nХеш-таблица с закрытой адресацией\n\t-Время поиска = " + CATableTime.ToString("F2") +
                "\n\t-Занимаемая память = " + CATable.getMemory() + " байт.");
            MessageBox.Show(Result.ToString());
            this.progressBar1.Value = 0;
        }
Ejemplo n.º 2
0
        private void CAHashTableSearch(int Key)
        {
            int Result = -1;
            Counter counter = new Counter();
            counter.Start();
            for (int i = 0; i < RepeatsCount; ++i)
                Result = CATable.Search(Key);
            counter.Stop();

            String StrResult;

            if (Result == -1)
                StrResult = "Ничего не найдено!";
            else
                StrResult = "Индекс элемента в массива = " + Result.ToString();

            MessageBox.Show(StrResult + "\nВремя поиска при " + RepeatsCount.ToString() +
                     " повторах = " + counter.TotalSeconds.ToString("F2"));
        }
Ejemplo n.º 3
0
        private void TreeSearch(AdvancedBTree<int> Tree, int Key)
        {
            Counter counter = new Counter();
            counter.Start();
            Node<int> Node = null;
            for (int i = 0; i < RepeatsCount; ++i)
                Node = Tree.Search(Key);
            counter.Stop();
            String Result;
            if (Node == null)
                Result = "Ничего не найдено";
            else
                Result = "Введенное число найдено на " +
                    AdvancedBTree<int>.NodeLevel(Node).ToString() + " уровне.";

            MessageBox.Show(Result + "\nВремя поиска при " + RepeatsCount.ToString() +
                     " повторах = " + counter.TotalSeconds.ToString("F2"));
        }
Ejemplo n.º 4
0
        private void button7_Click(object sender, EventArgs e)
        {
            const int RepeatsCount = 100;
            Counter timer = new Counter();
            int RowsNum = Convert.ToInt32(this.maskedTextBox3.Text);
            int ColsNum = Convert.ToInt32(this.maskedTextBox2.Text);
            Matrix TestMatrix = new Matrix(RowsNum, ColsNum);
            int Percentage = Convert.ToInt32(this.maskedTextBox1.Text);
            TestMatrix.GenerateRandom(Percentage);
            SparseMatrix TestSpMatrix = new SparseMatrix(TestMatrix);
            Random rand = new Random();
            Double[] TestVector = new Double[ColsNum];
            for (int i = 0; i < ColsNum; ++i)
                TestVector[i] = rand.Next();
            this.progressBar1.Value = 0;
            int Step = 5;
            int PercentPart = 2 * Step * RepeatsCount / 100;

            // Время для обычных матриц
            timer.Reset();
            timer.Start();
            for (int i = 0; i < RepeatsCount; ++i)
            {
                TestMatrix.MulToVector(TestVector);
                if (i % PercentPart == 0)
                    this.progressBar1.Value += Step;
            }
            timer.Stop();

            float Time1 = timer.TotalSeconds;
            this.richTextBox3.Text += "\nВремя умножения для обычных матриц (" + this.maskedTextBox1.Text +
                "% ненулевых элементов): " + Time1.ToString("F3") + ";\nПамять: " + TestMatrix.getSizeOfThis().ToString() +
                " байт на матрицу.";
          
            // Время для разреженных матриц
            timer.Reset();
            timer.Start();
            for (int i = 0; i < RepeatsCount; ++i)
            {
                TestSpMatrix.MulToVector(TestVector);
                if (i % PercentPart == 0)
                    this.progressBar1.Value += Step;
            }
            timer.Stop();
            float Time2 = timer.TotalSeconds;
            this.richTextBox3.Text += "\nВремя умножения для разреженных матриц (" + this.maskedTextBox1.Text +
                "% ненулевых элементов): " + Time2.ToString("F3") + ";\nПамять: " + TestSpMatrix.getSizeOfThis().ToString() +
                " байт на матрицу.";

            int PercentDelta = (int)(((Double) (Time1 / Time2) - 1) * 100);
            this.richTextBox3.Text += "\nУмножение обычных матриц медленнее на : " + PercentDelta.ToString() + "%";

            Double temp = (Double)TestMatrix.getSizeOfThis() / (Double)TestSpMatrix.getSizeOfThis();
            int MemoryPercent = (int)((temp - 1) * 100);
            this.richTextBox3.Text += "\nОбычная матрица занимает памяти больше на : " + MemoryPercent.ToString() + "%\n";

        }
Ejemplo n.º 5
0
        // Сравнение сортировок и поиска
        private void button1_Click(object sender, EventArgs e)
        {
            AdvancedBTree<int> TestTree = new AdvancedBTree<int>();
            Random rand = new Random();
            Counter counter = new Counter();
            const int MaxNum = 100;
            const int RepeatsLimit = 10000;

            // Для дерева высотой 10
            while (TestTree.Depth() != 10)
                TestTree.Insert(rand.Next(MaxNum));

            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.Search(rand.Next(MaxNum));
            counter.Stop();
            double Search10Time = counter.TotalSeconds;

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.GetSortedList();
            counter.Stop();
            double Sort10Time = counter.TotalSeconds;
            this.progressBar1.Value += 20;

            // Для дерева высотой 20
            TestTree = new AdvancedBTree<int>();
            while (TestTree.Depth() != 20)
                TestTree.Insert(rand.Next(MaxNum));
            
            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.Search(rand.Next(MaxNum));
            counter.Stop();
            double Search20Time = counter.TotalSeconds;

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.GetSortedList();
            counter.Stop();
            double Sort20Time = counter.TotalSeconds;
            this.progressBar1.Value += 20;

            // Для дерева высотой 50
            TestTree = new AdvancedBTree<int>();
            while (TestTree.Depth() != 50)
                TestTree.Insert(rand.Next(MaxNum));

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.Search(rand.Next(MaxNum));
            counter.Stop();
            double Search50Time = counter.TotalSeconds;

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.GetSortedList();
            counter.Stop();
            double Sort50Time = counter.TotalSeconds;
            this.progressBar1.Value += 20;

            // Сравнение сортировки и добавления при разных степенях ветвления
            const int TestDepth = 100;

            // Для сильного ветвления
            TestTree = new AdvancedBTree<int>();
            while (TestTree.Depth() != TestDepth)
                TestTree.Insert(rand.Next(MaxNum));

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.Search(rand.Next(MaxNum));
            counter.Stop();
            double SearchGoodTime = counter.TotalSeconds;

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.GetSortedList();
            counter.Stop();
            double SortGoodTime = counter.TotalSeconds;
            this.progressBar1.Value += 20;

            // Для слабого ветвления
            TestTree = new AdvancedBTree<int>();
            int j = 0;
            while (TestTree.Depth() != TestDepth)
                TestTree.Insert(j++);

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.Search(rand.Next(MaxNum));
            counter.Stop();
            double SearchBadTime = counter.TotalSeconds;

            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatsLimit; ++i)
                TestTree.GetSortedList();
            counter.Stop();
            double SortBadTime = counter.TotalSeconds;
            this.progressBar1.Value += 20;

            // Вывод результата
            String Result = "Сравнение в зависимости от глубины дерева:\r\n" +
                "  Глубина 10:\r\n" +
                "    Время поиска = " + Search10Time.ToString("F2") + "\r\n" +
                "    Время сортировки = " + Sort10Time.ToString("F2") + "\r\n" +
                "  Глубина 20:\r\n" +
                "    Время поиска = " + Search20Time.ToString("F2") + "\r\n" +
                "    Время сортировки = " + Sort20Time.ToString("F2") + "\r\n" +
                "  Глубина 50:\r\n" +
                "    Время поиска = " + Search50Time.ToString("F2") + "\r\n" +
                "    Время сортировки = " + Sort50Time.ToString("F2") + ".\r\n" +
                "Сравнение в зависимости от степени ветвления дерева:\r\n" +
                "  Плохая степень ветвления:\r\n" +
                "    Время поиска = " + SearchBadTime.ToString("F2") + "\r\n" +
                "    Время сортировки = " + SortBadTime.ToString("F2") + "\r\n" +
                "  Отличная степень ветвления:\r\n" +
                "    Время поиска = " + SearchGoodTime.ToString("F2") + "\r\n" +
                "    Время сортировки = " + SortGoodTime.ToString("F2") + "\r\n";
            MessageBox.Show(Result);
            this.progressBar1.Value = 0;
        }
Ejemplo n.º 6
0
        // Сравнение времени добавления
        private void button4_Click(object sender, EventArgs e)
        {
            const int RepeatLimit = 1000;
            const int Limit2 = 10;
            const String TestFileName = "Comparing.txt";
            String Test = "";
            System.IO.StreamWriter file = new System.IO.StreamWriter(TestFileName);
            const int Number = 4;
            BTree<int> Tree = new BTree<int>();

            Counter counter = new Counter();

            // Настройки для ПрогрессБара
            const int PercentStep = 5;
            const int OnePart = RepeatLimit / (2 * PercentStep);

            // Время добавления в файл
            counter.Start();
            for (int i = 0; i < RepeatLimit; ++i)
            {
                for (int j = 0; j < Limit2; ++j)
                {
                    Test += " " + Number.ToString();
                    file.Write(Test);
                }

                if (i % OnePart == 0)
                    progressBar1.Value += PercentStep;
            }
            counter.Stop();
            double FileAddTime = counter.TotalSeconds;

            // Время добавления в бинарное дерево
            counter.Reset();
            counter.Start();
            for (int i = 0; i < RepeatLimit; ++i)
            {
                for (int j = 0; j < Limit2; ++j)
                    Tree.Insert(Number);
                if (i % OnePart == 0)
                    progressBar1.Value += PercentStep;
            }
            counter.Stop();
            double TreeAddTime = counter.TotalSeconds;

            // Выод времени
            String Result = "Время добавления числа при " + RepeatLimit.ToString() + " повторах:\r\n  В файл -> " +
                FileAddTime.ToString("F2") + " секунд\r\n  В бинарное дерево -> " + TreeAddTime.ToString("F2") + " секунд";
            MessageBox.Show(Result);
            this.progressBar1.Value = 0;
            file.Close();
        }