public void Test()
 {
     var logger = new AccumulationLogger();
     var config = DefaultConfig.Instance.With(logger);
     // System.InvalidOperationException : Property "StaticParamProperty" must be public and writable if it has the [Params(..)] attribute applied to it
     Assert.Throws<InvalidOperationException>(() => BenchmarkRunner.Run(this.GetType(), config));
 }
Пример #2
0
 public void Test()
 {
     var logger = new AccumulationLogger();
     var config = DefaultConfig.Instance.With(logger);
     BenchmarkTestExecutor.CanExecute<SetupAttributeTest>(config);
     Assert.Contains("// ### Setup called ###" + Environment.NewLine, logger.GetLog());
 }
        public void Test()
        {
            var logger = new AccumulationLogger();
            var config = DefaultConfig.Instance.With(logger);
            var summary = BenchmarkRunner.Run<PerformanceUnitTest>(config);

            // Sanity checks, to be sure that the different benchmarks actually run
            var testOutput = logger.GetLog();
            Assert.Contains("// ### Slow Benchmark called ###" + Environment.NewLine, testOutput);
            Assert.Contains("// ### Fast Benchmark called ###" + Environment.NewLine, testOutput);

            // Check that slow benchmark is actually slower than the fast benchmark!
            var slowBenchmarkRun = summary.GetRunsFor<PerformanceUnitTest>(r => r.SlowBenchmark()).First();
            var fastBenchmarkRun = summary.GetRunsFor<PerformanceUnitTest>(r => r.FastBenchmark()).First();
            Assert.True(slowBenchmarkRun.GetAverageNanoseconds() > fastBenchmarkRun.GetAverageNanoseconds(),
                        string.Format("Expected SlowBenchmark: {0:N2} ns to be MORE than FastBenchmark: {1:N2} ns",
                                      slowBenchmarkRun.GetAverageNanoseconds(), fastBenchmarkRun.GetAverageNanoseconds()));
            Assert.True(slowBenchmarkRun.GetOpsPerSecond() < fastBenchmarkRun.GetOpsPerSecond(),
                        string.Format("Expected SlowBenchmark: {0:N2} Ops to be LESS than FastBenchmark: {1:N2} Ops",
                                      slowBenchmarkRun.GetOpsPerSecond(), fastBenchmarkRun.GetOpsPerSecond()));

            // Whilst we're at it, let's do more specific Asserts as we know what the elasped time should be
            var slowBenchmarkReport = summary.GetReportFor<PerformanceUnitTest>(r => r.SlowBenchmark());
            var fastBenchmarkReport = summary.GetReportFor<PerformanceUnitTest>(r => r.FastBenchmark());
            foreach (var slowRun in slowBenchmarkReport.GetResultRuns())
                Assert.InRange(slowRun.GetAverageNanoseconds() / 1000.0 / 1000.0, low: 98, high: 102);
            foreach (var fastRun in fastBenchmarkReport.GetResultRuns())
                Assert.InRange(fastRun.GetAverageNanoseconds() / 1000.0 / 1000.0, low: 14, high: 17);
        }
 private Summary CreateSummary(IConfig config)
 {
     var logger = new AccumulationLogger();
     var summary = MockFactory.CreateSummary(config);
     MarkdownExporter.Default.ExportToLog(summary, logger);
     output.WriteLine(logger.GetLog());
     return summary;
 }
 public static void Test()
 {
     var logger = new AccumulationLogger();
     var config = DefaultConfig.Instance.With(logger);
     BenchmarkRunner.Run<ParamsTestStaticField>(config);
     foreach (var param in new[] { 1, 2 })
         Assert.Contains($"// ### New Parameter {param} ###" + Environment.NewLine, logger.GetLog());
     Assert.DoesNotContain($"// ### New Parameter 0 ###" + Environment.NewLine, logger.GetLog());
 }
 public void Test()
 {
     var logger = new AccumulationLogger();
     var config = DefaultConfig.Instance.With(logger);
     BenchmarkTestExecutor.CanExecute<ParamsTestProperty>(config);
     foreach (var param in new[] { 1, 2 })
         Assert.Contains($"// ### New Parameter {param} ###" + Environment.NewLine, logger.GetLog());
     Assert.DoesNotContain($"// ### New Parameter {default(int)} ###" + Environment.NewLine, logger.GetLog());
 }
Пример #7
0
 public void Test()
 {
     var logger = new AccumulationLogger();
     var config = DefaultConfig.Instance.With(logger);
     // Run our F# test that lives in "BenchmarkDotNet.IntegrationTests.FSharp"
     BenchmarkRunner.Run<FSharpBenchmark.Db>(config);
     var testLog = logger.GetLog();
     Assert.Contains("// ### F# Benchmark method called ###", testLog);
     Assert.DoesNotContain("No benchmarks found", testLog); // TODO: move message to const for all of the test
 }
 private SummaryTable CreateTable()
 {
     var logger = new AccumulationLogger();
     var config = DefaultConfig.Instance;
     var summary = MockFactory.CreateSummary(config);
     var table = new SummaryTable(summary);
     MarkdownExporter.Default.ExportToLog(summary, logger);
     output.WriteLine(logger.GetLog());
     return table;
 }
        public void Test()
        {
            var logger = new AccumulationLogger();
            var sourceDiagnoser = new SourceDiagnoser();
            var config = DefaultConfig.Instance.With(logger).With(sourceDiagnoser);
            BenchmarkRunner.Run<SourceDiagnoserTest>(config);

            var testOutput = logger.GetLog();
            Assert.Contains($"Printing Code for Method: {this.GetType().FullName}.DictionaryEnumeration()", testOutput);
            Assert.Contains("PrintAssembly=True", testOutput);
        }
        private void Verify(Platform platform, Type benchmark, string failureText)
        {
            var logger = new AccumulationLogger();
            var config = new PlatformConfig(platform).With(logger);

            BenchmarkRunner.Run(benchmark, config);
            var testLog = logger.GetLog();

            Assert.DoesNotContain(failureText, testLog);
            Assert.DoesNotContain(BenchmarkNotFound, testLog);
        }
        public void Test()
        {
            var logger = new AccumulationLogger();
            var testExporter = new TestExporter();
            var config = DefaultConfig.Instance.With(logger).With(testExporter);
            BenchmarkRunner.Run(this.GetType(), config);

            // Ensure that when the TestBenchmarkExporter() was run, it wasn't passed an instance of "BenchmarkBaselineDeltaResultExtender"
            Assert.False(testExporter.ExportCalled);
            Assert.True(testExporter.ExportToFileCalled);
        }
        private void Verify(Platform platform, Type benchmark, string failureText)
        {
            var logger = new AccumulationLogger();
            // make sure we get an output in the TestRunner log
            var config = new PlatformConfig(platform).With(logger).With(ConsoleLogger.Default);

            BenchmarkTestExecutor.CanExecute(benchmark, config);
            var testLog = logger.GetLog();

            Assert.DoesNotContain(failureText, testLog);
            Assert.DoesNotContain(BenchmarkNotFound, testLog);
        }
Пример #13
0
        public void Test()
        {
            var logger = new AccumulationLogger();
            var config = DefaultConfig.Instance.With(logger);

            BenchmarkRunner.Run<ModeTests>(config);
            var testLog = logger.GetLog();

            Assert.Contains("// ### BenchmarkSingleRunVoid method called ###", testLog);
            Assert.Contains("// ### BenchmarkSingleRunWithReturnValue method called ###", testLog);

            Assert.Contains("// ### BenchmarkSingleRunVoid method called ###", testLog);
            Assert.Contains("// ### BenchmarkSingleRunWithReturnValue method called ###", testLog);

            Assert.DoesNotContain("No benchmarks found", logger.GetLog());
        }
        public void Test()
        {
            var logger = new AccumulationLogger();
            var columns = new[]
            {
                StatisticColumn.StdDev,
                StatisticColumn.Min,
                StatisticColumn.Q1,
                StatisticColumn.Median,
                StatisticColumn.Q3,
                StatisticColumn.Max,
                StatisticColumn.OperationsPerSecond
            };
            var config = DefaultConfig.Instance.With(logger).With(columns);
            var summary = BenchmarkRunner.Run<Target>(config);
            output.WriteLine(logger.GetLog());

            var table = summary.Table;
            var headerRow = table.FullHeader;
            foreach (var column in columns)
                Assert.True(headerRow.Contains(column.ColumnName));
        }
 public static void Test()
 {
     var logger = new AccumulationLogger();
     var config = DefaultConfig.Instance.With(logger);
     // System.InvalidOperationException : Field "StaticParamField" must be public if it has the [Params(..)] attribute applied to it
     Assert.Throws<InvalidOperationException>(() => BenchmarkRunner.Run<ParamsTestStaticPrivateField>(config));
 }