Ejemplo n.º 1
0
        static void SimpleTreeInt(string path)
        {
            int pointsCount = 2, pointsDistance = 1000000;

            int[][] results = { new int[pointsCount], new int[pointsCount], new int[pointsCount] };
            for (int i = 1, j = 0; j < pointsCount; i += pointsDistance, j++)
            {
                if (File.Exists(path + "simple int.pac"))
                {
                    File.Delete(path + "simple int.pac");
                }
                if (File.Exists(path + "simple int tree.pxc"))
                {
                    File.Delete(path + "simple int tree.pxc");
                }
                if (File.Exists(path + "simple int tree add.pxc"))
                {
                    File.Delete(path + "simple int tree add.pxc");
                }

                Thread.Sleep(1);
                var       objects = Enumerable.Range(0, i).Cast <object>().ToArray();
                Stopwatch timer   = new Stopwatch();
                var       ints    = objects.Cast <int>();
                timer.Start();
                var simpleIntCell = new BTreeInt(new PType(PTypeEnumeration.integer),
                                                 path + "simple int tree.pxc", false);
                simpleIntCell.Fill(ints, false);
                //objects.ToBTree(new PType(PTypeEnumeration.integer), path + "simple int tree.pxc",
                //(o, entry) => (int) o - (int) entry.Get(), o => o, false);
                timer.Stop();
                results[0][j] = (int)timer.Elapsed.Ticks;
                Console.WriteLine("simple int tree " + i + "elements created for (ms)" + timer.Elapsed.TotalMilliseconds);
                timer.Restart();
                PaCell paCell = new PaCell(new PTypeSequence(new PType(PTypeEnumeration.integer)),
                                           path + "simple int.pac", false);
                paCell.Fill(objects);
                timer.Stop();
                results[1][j] = (int)timer.Elapsed.Ticks;
                Console.WriteLine("simple int pa " + i + "elements created for (ms)" + timer.Elapsed.TotalMilliseconds);

                // линейное возрастание времени
                // AddTreeAddChart(path, timer, objects, results, j);
                Console.WriteLine();
                TestGetByKey(simpleIntCell, i, paCell);
                Console.WriteLine();
                paCell.Close();
                simpleIntCell.Close();
            }
        }
Ejemplo n.º 2
0
        private static void TestGetByKey(BTreeInt tree, int max, PaCell paCell)
        {
            Stopwatch timer = new Stopwatch();

            for (int i = 0; i < 3; i++)
            {
                if (i == 0)
                {
                    Console.WriteLine("first search");
                }
                int tested = new Random(DateTime.Now.Millisecond).Next(max - 1);
                timer.Restart();
                var res = tree.BinarySearch(tested);
                timer.Stop();
                Console.WriteLine("search in " + max + " elements TREE find " + tested + " for (ticks)" + timer.Elapsed.Ticks);
                timer.Restart();
                var res1 = paCell.Root.BinarySearchFirst(entry => (int)entry.Get() - tested);
                timer.Stop();
                Console.WriteLine("binary search in " + max + " elements PA CELL find " + tested + " for (ticks)" + timer.Elapsed.Ticks);
                Console.WriteLine();
            }
        }