コード例 #1
0
ファイル: TestMethods.cs プロジェクト: ndpdev/prefixsearch
        public void SearchIPv4PrefixMap(IPv4PrefixMap map)
        {
            int threadCount       = Math.Max(Environment.ProcessorCount - 1, 2);
            int searchesPerThread = settings.Value.SearchCount / threadCount;

            //TODO: Convert to PLINQ expression?
            var sw      = Stopwatch.StartNew();
            var batches = Enumerable.Range(1, threadCount)
                          .Select(id => Task.Run(() => map.FindNetworks(id, GenerateRandomIPAddresses(searchesPerThread)).ToList()))
                          .ToArray();

            Task.WaitAll(batches);
            sw.Stop();

            long searchTime       = sw.ElapsedMilliseconds;
            var  totalResultCount = batches.Select(x => x.Result.Count).Sum();
            var  results          = batches.SelectMany(x => x.Result.Take(5));

            Console.WriteLine("Sample Search Results");
            foreach (var x in results)
            {
                string block   = $"{x.Prefix} ({(x.Prefix.HasFlag ? "Azure" : "Amazon")})";
                string message = $" * [{x.Thread}] ip: {IPv4.ConvertToString(x.Address),-17} net: {block,-27} miss: {x.Counter,-5}";
                Console.WriteLine(message);
            }

            Console.WriteLine();
            Console.WriteLine($"Found {totalResultCount} matching addresses in {map.Count} distinct prefixes ({searchTime} ms)");
        }
コード例 #2
0
ファイル: TestMethods.cs プロジェクト: ndpdev/prefixsearch
        public void ParseIPAddress()
        {
            var testAddress = settings.Value.TestAddress;
            var testCount   = settings.Value.TestCount;

            var ip = IPv4.ParseIP(testAddress);

            Console.WriteLine($"Test: {IPv4.ConvertToBitString(ip)} {IPv4.ConvertToString(ip)} [ParseIPAddress address:{testAddress}]");

            var sw = Stopwatch.StartNew();

            for (int i = 0; i < testCount; i++)
            {
                _ = IPv4.ParseIP(testAddress);
            }
            Console.WriteLine($" - {sw.ElapsedMilliseconds} ms");
        }