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); }
/// <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()); }