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); }
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); } }
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); }
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); }
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(); }
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(); }