예제 #1
0
        public void InnerDataSourceSearch()
        {
            Helper.PrintMem();

            var searcher = MobilePhoneFactory.GetSearcher();

            //预热
            searcher.TryGet("13702331111", out var info);
            searcher.Search(1370233);

            Helper.Time("单条查询", () =>
            {
                searcher.Search(1370233);
            });

            int count = 20000000;

            Helper.Time("批量查询", () =>
            {
                searcher.Search(1370233);
            }, count);

            Helper.TimeWithParallel("并发查询", () =>
            {
                searcher.Search(1370233);
            }, count);

            Helper.TimeWithThread("多线程查询", () =>
            {
                searcher.Search(1370233);
            }, 4, count);
        }
예제 #2
0
        static void Main(string[] args)
        {
            var filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "phones.txt");
            var dest     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MobilePhoneRegion.dat");

            using (var fs = File.Create(dest))
            {
                MobilePhoneFactory.Generate(MobilePhoneRegion.Version.V2, GetPhoneList(filename).ToArray(), fs);
            }

            Console.WriteLine("done.");
        }
예제 #3
0
        public void Check_ALL_Match_Inner_DataSource()
        {
            var filename = Path.Combine(AppContext.BaseDirectory, "phones.txt");
            var data     = Helper.GetPhoneList(filename).ToArray();

            var          searcher = MobilePhoneFactory.GetSearcher();
            SearchResult result;

            foreach (var info in data)
            {
                result = searcher.Search(info.Phone);
                Assert.True(result.Success);
            }
        }
예제 #4
0
        public void Check_Mobile17X()
        {
            var searcher = MobilePhoneFactory.GetSearcher();

            var result = searcher.TryGet("17093318888", out MobilePhone info);

            Assert.True(result);

            result = searcher.TryGet("16677408888", out info);
            Assert.True(result);

            result = searcher.TryGet("19893318888", out info);
            Assert.True(result);

            result = searcher.TryGet("19999798888", out info);
            Assert.True(result);
        }
예제 #5
0
        public void StreamDataSourceSearch()
        {
            Helper.PrintMem();

            var dest = Path.Combine(AppContext.BaseDirectory, "MobilePhoneRegion.dat");

            if (!File.Exists(dest))
            {
                var filename = Path.Combine(AppContext.BaseDirectory, "phones.txt");

                using (var fs = File.Create(dest))
                {
                    MobilePhoneFactory.Generate(MobilePhoneRegion.Version.V2, Helper.GetPhoneList(filename).ToArray(), fs);
                }
            }

            var dataSource = new StreamDataSource(dest);

            var searcher = MobilePhoneFactory.GetSearcher(dataSource);

            //预热
            searcher.TryGet("13702331111", out var info);
            searcher.Search(1370233);

            Helper.Time("单条查询", () =>
            {
                searcher.Search(1370233);
            });

            int count = 10000;

            Helper.Time("批量查询", () =>
            {
                searcher.Search(1370233);
            }, count);

            Helper.TimeWithParallel("并发查询", () =>
            {
                searcher.Search(1370233);
            }, count);

            Helper.TimeWithThread("多线程查询", () =>
            {
                searcher.Search(1370233);
            }, 4, count);
        }
예제 #6
0
        public void Writer_And_Reader_V1()
        {
            var filename = Path.Combine(AppContext.BaseDirectory, "phones.txt");
            var dest     = Path.Combine(AppContext.BaseDirectory, "v1.dat");

            using (var fs = File.Create(dest))
            {
                MobilePhoneFactory.Generate(MobilePhoneRegion.Version.V2, Helper.GetPhoneList(filename).ToArray(), fs);
            }

            var dataSource = new StreamDataSource(dest);

            var searcher = MobilePhoneFactory.GetSearcher(dataSource);

            var result = searcher.Search(1370233);

            Assert.True(result.Success);

            dataSource.Dispose();
        }
예제 #7
0
        public void Check_ALL_Match_V2()
        {
            var filename = Path.Combine(AppContext.BaseDirectory, "phones.txt");
            var dest     = Path.Combine(AppContext.BaseDirectory, "v2.dat");
            var data     = Helper.GetPhoneList(filename).ToArray();

            using (var fs = File.Create(dest))
            {
                MobilePhoneFactory.Generate(MobilePhoneRegion.Version.V2, data, fs);
            }

            var dataSource = new MemoryDataSource(dest);

            var          searcher = MobilePhoneFactory.GetSearcher(dataSource);
            SearchResult result;

            foreach (var info in data)
            {
                result = searcher.Search(info.Phone);
                Assert.True(result.Success);
            }

            dataSource.Dispose();
        }