コード例 #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 BenchmarkFactoryFromTypes(BenchmarkOptions options, IEnumerable <Type> types)
            : base(options)
        {
            Debug.Assert(options != null);
            Debug.Assert(types != null);

            if (types.Any(x => !IsEligibleBenchmarkType(x)))
            {
                throw new ArgumentException("Cannot use dynamic assemblies or assemblies loaded from a byte stream.");
            }

            _types = types;
        }
コード例 #4
0
        /// <summary>
        /// Creates a new <see cref="BenchmarkEngine"/> object using specified benchmarks.
        /// </summary>
        /// <param name="options">Options for this engine to define how benchmark are searched and executed.</param>
        /// <param name="assemblies">
        /// List of all types which implement a benchmark, note that for method discovering each type must still respect
        /// <see cref="BenchmarkOptions.SearchMethod"/> value.
        /// </param>
        public BenchmarkEngine(BenchmarkOptions options, IEnumerable <Type> benchmarks)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (benchmarks == null)
            {
                throw new ArgumentNullException("benchmarks");
            }

            Options  = options;
            _factory = new BenchmarkFactoryFromTypes(options, benchmarks);
        }
コード例 #5
0
        /// <summary>
        /// Creates a new <see cref="BenchmarkEngine"/> object searching for benchmarks in all specified assemblies.
        /// </summary>
        /// <param name="options">Options for this engine to define how benchmark are searched and executed.</param>
        /// <param name="assemblies">List of assemblies on which you want to search benchmarks.</param>
        public BenchmarkEngine(BenchmarkOptions options, IEnumerable <Assembly> assemblies)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (assemblies == null)
            {
                throw new ArgumentNullException("assemblies");
            }

            Options  = options;
            _factory = new BenchmarkFactoryFromAssemblies(options, assemblies);
        }
コード例 #6
0
        protected BenchmarkFactory(BenchmarkOptions options)
        {
            Debug.Assert(options != null);

            _options = options;
        }