コード例 #1
0
        private static void PerformSingleBenchmark(Benchmark benchmark, BenchmarkedMethod method, BenchmarkPerformer performer)
        {
            Debug.Assert(benchmark != null);
            Debug.Assert(method != null);
            Debug.Assert(performer != null);

            performer.SetUpMethods      = benchmark.SetUpMethods;
            performer.CleanUpMethods    = benchmark.CleanUpMethods;
            performer.MethodToBenchmark = method.Method;

            method.Measures.Add(performer.Run());
        }
コード例 #2
0
        private BenchmarkedMethod CreateBenchmarkForMethod(MethodInfo method, BenchmarkedMethodAttribute descriptor)
        {
            Debug.Assert(method != null);

            var benchmarkedMethod = new BenchmarkedMethod();

            benchmarkedMethod.Method = method;

            benchmarkedMethod.Name        = ResolveValue(descriptor, () => descriptor.Name, method.Name);
            benchmarkedMethod.Description = ResolveValue(descriptor, () => descriptor.Name, method.Name);
            benchmarkedMethod.WarmUp      = ResolveValue(descriptor, () => descriptor.WarmUp, null) ?? _options.WarmUp;
            benchmarkedMethod.Repetitions = ResolveValue(descriptor, () => descriptor.Repetitions, null) ?? _options.Repetitions;

            return(benchmarkedMethod);
        }
コード例 #3
0
        public static void AccumulateResults(BenchmarkEngine engine, Benchmark benchmark, BenchmarkedMethod method)
        {
            Debug.Assert(method != null);

            for (int i = 0; i < method.Repetitions; ++i)
            {
                if (engine.Options.RunTestsInIsolation)
                {
                    PerformSingleBenchmarkOnSeparateAppDomain(benchmark, method);
                }
                else
                {
                    PerformSingleBenchmarkOnThisAppDomain(benchmark, method);
                }
            }
        }
コード例 #4
0
        private static void PerformSingleBenchmarkOnThisAppDomain(Benchmark benchmark, BenchmarkedMethod method)
        {
            PerformSingleBenchmark(benchmark, method, new BenchmarkPerformer(method.WarmUp));

            // We do this to try to minimize GC impact on subsequent calls otherwise we may measure
            // the payload of THIS test on the NEXT one.
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
コード例 #5
0
        private static void PerformSingleBenchmarkOnSeparateAppDomain(Benchmark benchmark, BenchmarkedMethod method)
        {
            Debug.Assert(method != null);

            // CHECK: check if approach with AppDomain.DoCallback() is clearer
            var appDomain = CreateAppDomainForTest();

            try
            {
                var performer = (BenchmarkPerformer)(appDomain).CreateInstanceFromAndUnwrap(
                    typeof(BenchmarkPerformer).Assembly.Location, typeof(BenchmarkPerformer).FullName,
                    true, BindingFlags.Default, null, new object[] { method.WarmUp }, CultureInfo.CurrentCulture, null);

                PerformSingleBenchmark(benchmark, method, performer);
            }
            finally
            {
                AppDomain.Unload(appDomain);
            }
        }