コード例 #1
0
        public static string ExecuteAndRenderWithDefaults(string outputPath = null, BenchmarkOptions options = null)
        {
            string templatePath = Path.Combine(Environment.CurrentDirectory, HtmlOutputRenderer.DefaultReportName);

            if (String.IsNullOrWhiteSpace(outputPath))
            {
                outputPath = Path.Combine(Path.GetTempPath(), HtmlOutputRenderer.DefaultReportName);
            }

            var engine = new BenchmarkEngine(options ?? new BenchmarkOptions {
                SearchMethod = BencharkSearchMethod.Convention
            },
                                             new Assembly[] { Assembly.GetCallingAssembly() });

            var renderer = new HtmlOutputRenderer();

            renderer.TemplatePath = templatePath;
            renderer.Statistics   = new BasicStatistics()
            {
                CutTails = true
            };
            renderer.RenderTo(outputPath, engine.Execute());

            return(outputPath);
        }
コード例 #2
0
        /// <summary>
        /// Executes one benchmark in the given type and calculates average execution time.
        /// </summary>
        /// <param name="type">
        /// Type which contains the method to benchmark. This method must contain exactly one method to benchmark and
        /// it may be decorated with <c>BenchmarkedMethodAttribute</c>. Its name has to start with
        /// <c>Test</c> or to be the only public eligible method in the class.
        /// </param>
        /// <param name="options">Options, if omitted then default <see cref="BenchmarkOptions"/> are used.</param>
        /// <returns>
        /// The average execution time for the benchmark contained in the specified type.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="type"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="InvalidOperationException">
        /// If <paramref name="type"/> does not contain exactly one method to benchmark (public non-virtual instance method
        /// with name that starts with <c>Test</c>, name constraint is not mandatory if there is only one public method).
        /// </exception>
        public static TimeSpan ExecuteSingle(Type type, BenchmarkOptions options = null)
        {
            var engine = new BenchmarkEngine(options ?? new BenchmarkOptions {
                SearchMethod = BencharkSearchMethod.Convention
            },
                                             new Type[] { type });

            var benchmark         = engine.Execute().Single();
            var benchmarkedMethod = benchmark.Methods.Single();

            return(benchmarkedMethod.Measures.Average());
        }
コード例 #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
        /// <summary>
        /// Performs this benchmark.
        /// </summary>
        /// <param name="engine">The engine on which this benchmark is performed.</param>
        internal void Perform(BenchmarkEngine engine)
        {
            Debug.Assert(engine != null);

            var startTimestamp = DateTime.UtcNow;

            for (int i = 0; i < Methods.Count; ++i)
            {
                int progress = (int)((float)i / Methods.Count * 100);

                engine.OnBenchmarkProgressChanged(new ProgressChangedEventArgs(progress, Methods[i].Name));
                BenchmarkPerformer.AccumulateResults(engine, this, Methods[i]);
            }

            ExecutionTime = DateTime.UtcNow - startTimestamp;
        }