Beispiel #1
0
        /// <summary>
        /// Start measuring task that executes query and measures its latency.
        /// </summary>
        /// <param name="resolver">Resolver implementation being tested</param>
        /// <param name="domain">Domain to be resolved</param>
        /// <returns>Task which yields TestResult representing this test</returns>
        static Task <TestResult> MeasureQuery(IRecursiveResolver resolver, string domain)
        {
            Stopwatch stopwatch = Stopwatch.StartNew();
            var       t         = resolver.ResolveRecursive(domain);

            return(t.ContinueWith <TestResult>(t => {
                stopwatch.Stop();
                return new TestResult(domain, t.Result, stopwatch.ElapsedMilliseconds);
            }));
        }
Beispiel #2
0
 /// <summary>
 /// Start measuring task that executes query and measures its latency.
 /// </summary>
 /// <param name="resolver">Resolver implementation being tested</param>
 /// <param name="domain">Domain to be resolved</param>
 /// <returns>Task which yields TestResult representing this test</returns>
 static Task <TestResult> MeasureQuery(IRecursiveResolver resolver, string domain)
 {
     return(Task <TestResult> .Run(() => {
         Stopwatch stopwatch = Stopwatch.StartNew();
         var t = resolver.ResolveRecursive(domain);
         t.Wait();
         stopwatch.Stop();
         return new TestResult(domain, t.Result, stopwatch.ElapsedMilliseconds);
     }));
 }
Beispiel #3
0
        /// <summary>
        /// Run a batch of queries simultaneously and wait for them all to finish.
        /// </summary>
        /// <param name="resolver">Resolver implementation being tested</param>
        /// <param name="domains">Array of domains to be resolved</param>
        static void RunTestBatch(IRecursiveResolver resolver, string[] domains)
        {
            Console.Write("Starting ... ");
            var tests = domains.Select(domain => MeasureQuery(resolver, domain)).ToArray();

            Console.WriteLine("{0} tests", tests.Length);
            Task.WaitAll(tests);

            foreach (var test in tests)
            {
                Console.WriteLine("Domain {0} has IP {1} (elapsed time {2} ms) ",
                                  test.Result.domain, test.Result.address, test.Result.elapsedMilliseconds);
            }
        }
Beispiel #4
0
        static long RunTestBatchNoPrintOut(IRecursiveResolver resolver, string[] domains)
        {
            var tests = domains.Select(domain => MeasureQuery(resolver, domain)).ToArray();

            Task.WaitAll(tests);

            long sum = 0;

            foreach (var test in tests)
            {
                sum += test.Result.elapsedMilliseconds;
            }
            if (tests.Length > 0)
            {
            }
            return(sum);
        }
Beispiel #5
0
        /// <summary>
        /// Run a batch of queries simultaneously and wait for them all to finish.
        /// </summary>
        /// <param name="resolver">Resolver implementation being tested</param>
        /// <param name="domains">Array of domains to be resolved</param>
        /// <returns>Sum of measured times (in milliseconds)</returns>
        static long RunTestBatch(IRecursiveResolver resolver, string[] domains)
        {
            Console.Write("Starting ... ");
            var tests = domains.Select(domain => MeasureQuery(resolver, domain)).ToArray();

            Console.WriteLine("{0} tests", tests.Length);
            Task.WaitAll(tests);

            long sum = 0;

            foreach (var test in tests)
            {
                Console.WriteLine("Domain {0} has IP {1} (elapsed time {2} ms) ",
                                  test.Result.domain, test.Result.address, test.Result.elapsedMilliseconds);
                sum += test.Result.elapsedMilliseconds;
            }
            if (tests.Length > 0)
            {
                Console.WriteLine("Avg delay {0} ms", sum / tests.Length);
            }
            return(sum);
        }