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