Пример #1
0
        protected override async Task <Tuple <decimal, string> > InvokeTestAsync(ExceptionAggregator aggregator)
        {
            BenchmarkEventSource.Log.BenchmarkStart(this.DisplayName, TestCase.Iterations);

            //inject ITracer instance if test method defines single parameter of type ITracer
            var testMethodParams = TestMethod.GetParameters();
            var hasTracerParam   = (testMethodParams.Length == 1 && testMethodParams[0].ParameterType == typeof(ITracer));
            var args             = hasTracerParam  ? new object[] { NullTracer.Instance } : null;

            //run the test once to make sure it's been jitted
            await new BenchmarkTestInvoker(Test, MessageBus, TestClass, ConstructorArguments, TestMethod, args, aggregator, CancellationTokenSource).RunAsync();

            decimal executionTime = 0;

            //starting from 1 so that iteration number appears correctly in ETW log
            for (int i = 1; i <= TestCase.Iterations; i++)
            {
                if (TestCase.CollectGargage)
                {
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    GC.Collect();
                }

                var stopwatchTracer = new StopwatchTracer();

                BenchmarkEventSource.Log.BenchmarkIterationStart(i);
                var invokerTime = await new BenchmarkTestInvoker(Test, MessageBus, TestClass, ConstructorArguments, TestMethod, hasTracerParam ? new object[] { stopwatchTracer } : null, aggregator, CancellationTokenSource).RunAsync();
                BenchmarkEventSource.Log.BenchmarkIterationStop(i);

                var stopwatchTime = stopwatchTracer.GetElapsed();

                if (stopwatchTime.HasValue)
                {
                    executionTime += stopwatchTime.Value;
                }
                else
                {
                    executionTime += invokerTime;
                }
            }

            var message = new DiagnosticMessage("{0} , Iterations : {1} , TotalMilliseconds : {2}", this.DisplayName, TestCase.Iterations, executionTime * 1000);

            diagnosticMessageSink.OnMessage(message);

            BenchmarkEventSource.Log.BenchmarkStop(this.DisplayName, TestCase.Iterations);
            return(Tuple.Create(executionTime, string.Empty));
        }
Пример #2
0
 public Disposer(StopwatchTracer tracer)
 {
     this.tracer = tracer;
 }