コード例 #1
0
ファイル: NameTableUniversal.cs プロジェクト: agmarchuk/Polar
        public static void Main8()
        {
            string path = "../../../Databases/";
            Console.WriteLine("Start NameTableUniversal.");
            NameTableUniversal ntu = new NameTableUniversal(path);
            int test = 4;

            if (test == 1)
            {
                string[] strs = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
                ntu.Expand(strs.Length, strs);
                ntu.BuildIndexes();
                ntu.Add("ten");
                Console.WriteLine(ntu.ToString());
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            System.Random rnd = new Random();

            if (test == 2)
            {
                // Тест на ввод данных
                var different_set_query = Enumerable.Range(0, 1000000).Select(i => i.ToString());
                sw.Restart();
                ntu.Expand(10, different_set_query);
                sw.Stop();
                System.Console.WriteLine("Load ok. Duration={0}", sw.ElapsedMilliseconds);
                sw.Restart();
                ntu.BuildIndexes();
                sw.Stop();
                System.Console.WriteLine("Build indexes ok. Duration={0}", sw.ElapsedMilliseconds);
                sw.Restart();
                for (int i = 0; i < 1000; i++)
                {
                    int code = ntu.GetCode(rnd.Next(1500000).ToString());
                    //Console.WriteLine(i);
                }
                sw.Stop();
                System.Console.WriteLine("1000 GetCodeByIndex ok. Duration={0}", sw.ElapsedMilliseconds);
            }

            if (test == 3)
            {
                string[] strs1 = { "zero", "one", "two", "three", "four", "five" };
                string[] strs2 = { "six", "seven", "eight", "nine" };
                //var query = Enumerable.Repeat<int>(0, 100000).Select(x => rnd.Next());
                sw.Restart();
                ntu.Expand(10, new string[0]);
                ntu.BuildIndexes();
                ntu.InsertPortion(strs1);
                ntu.InsertPortion(strs2);
                ntu.BuildScale();
                sw.Stop();
                Console.WriteLine(ntu.ToString());
                System.Console.WriteLine(" ok. Duration={0}", sw.ElapsedMilliseconds);
            }

            if (test == 4)
            {
                int portion = 500000;
                int nportions = 2;
                int limit = 1000000000;
                var query = new List<string>(Enumerable.Repeat<int>(0, portion).Select(x => rnd.Next(limit).ToString()));
                bool tobuild = true;
                if (tobuild)
                {
                    sw.Restart();
                    ntu.Expand(portion*nportions, new string[0]);
                    ntu.BuildIndexes();
                    for (int i = 0; i < nportions; i++)
                    {
                        ntu.InsertPortion(query);
                        Console.WriteLine("portion {0} ok.", i + 1);
                    }
                    ntu.BuildScale();
                    sw.Stop();
                    System.Console.WriteLine("Load-build ok. Duration={0}", sw.ElapsedMilliseconds);
                }
                else
                {
                    sw.Restart();
                    ntu.Warmup();
                    sw.Stop();
                    System.Console.WriteLine("Warmup ok. Duration={0} volume={1}", sw.ElapsedMilliseconds, ntu.table.TableCell.Root.Count());
                }
                sw.Restart();
                int number = 0;
                foreach (var s in query.Take(10000))
                {
                    int c = ntu.GetCode(s);
                    number += c < 0 ? 0 : 1;
                }
                sw.Stop();
                System.Console.WriteLine("10000 search ok. Duration={0} number={1}", sw.ElapsedMilliseconds, number);
            }

            // Выполним только после уже построенной таблицы имен. От нее должна остаться опорная таблица cstable.pac
            if (test == 5)
            {
                int portion = 500000;
                //int nportions = 2;
                int limit = 1000000000;
                var query = Enumerable.Repeat<int>(0, portion).Select(x => rnd.Next(limit).ToString());
                bool tobuild = true;
                if (tobuild)
                {
                    sw.Restart();
                    ntu.BuildIndexes();
                    sw.Stop();
                    System.Console.WriteLine("BuildIndexes ok. Duration={0}", sw.ElapsedMilliseconds);
                }
                else
                {
                    sw.Restart();
                    ntu.Warmup();
                    sw.Stop();
                    System.Console.WriteLine("Warmup ok. Duration={0} volume={1}", sw.ElapsedMilliseconds, ntu.table.TableCell.Root.Count());
                }
                sw.Restart();
                int number = 0;
                foreach (var s in query.Take(10000))
                {
                    int c = ntu.GetCode(s);
                    number += c < 0 ? 0 : 1;
                }
                sw.Stop();
                System.Console.WriteLine("10000 search ok. Duration={0} number={1}", sw.ElapsedMilliseconds, number);

            }
        }