public void Test()
 {
     var logger = new BenchmarkAccumulationLogger();
     var plugins = BenchmarkPluginBuilder.CreateDefault().AddLogger(logger).Build();
     // System.InvalidOperationException : Property "StaticParamProperty" must be public and writable if it has the [Params(..)] attribute applied to it
     Assert.Throws<InvalidOperationException>(() => new BenchmarkRunner(plugins).Run(this.GetType()));
 }
        public void Test()
        {
            var logger = new BenchmarkAccumulationLogger();
            var extenders = new[]
            {
                BenchmarkStatResultExtender.StdDev,
                BenchmarkStatResultExtender.Min,
                BenchmarkStatResultExtender.Q1,
                BenchmarkStatResultExtender.Median,
                BenchmarkStatResultExtender.Q3,
                BenchmarkStatResultExtender.Max,
                BenchmarkStatResultExtender.OperationPerSecond
            };
            var plugins = BenchmarkPluginBuilder.CreateDefault().
                AddLogger(logger).
                AddResultExtenders(extenders).
                Build();
            var reports = new BenchmarkRunner(plugins).Run<Target>().ToList();
            output.WriteLine(logger.GetLog());

            var table = BenchmarkExporterHelper.BuildTable(reports, plugins.ResultExtenders);
            var headerRow = table.First();
            foreach (var extender in extenders)
                Assert.True(headerRow.Contains(extender.ColumnName));
        }
        public void Test()
        {
            var logger = new BenchmarkAccumulationLogger();
            var plugins = BenchmarkPluginBuilder.CreateDefault().AddLogger(logger).Build();
            var reports = new BenchmarkRunner(plugins).Run<PerformanceUnitTest>();

            // 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 = reports.GetRunsFor<PerformanceUnitTest>(r => r.SlowBenchmark()).First();
            var fastBenchmarkRun = reports.GetRunsFor<PerformanceUnitTest>(r => r.FastBenchmark()).First();
            Assert.True(slowBenchmarkRun.AverageNanoseconds > fastBenchmarkRun.AverageNanoseconds,
                        string.Format("Expected SlowBenchmark: {0:N2} ns to be MORE than FastBenchmark: {1:N2} ns",
                                      slowBenchmarkRun.AverageNanoseconds, fastBenchmarkRun.AverageNanoseconds));
            Assert.True(slowBenchmarkRun.OpsPerSecond < fastBenchmarkRun.OpsPerSecond,
                        string.Format("Expected SlowBenchmark: {0:N2} Ops to be LESS than FastBenchmark: {1:N2} Ops",
                                      slowBenchmarkRun.OpsPerSecond, fastBenchmarkRun.OpsPerSecond));

            // Whilst we're at it, let's do more specific Asserts as we know what the elasped time should be
            var slowBenchmarkReport = reports.GetReportFor<PerformanceUnitTest>(r => r.SlowBenchmark());
            var fastBenchmarkReport = reports.GetReportFor<PerformanceUnitTest>(r => r.FastBenchmark());
            foreach (var slowRun in slowBenchmarkReport.Runs)
                Assert.InRange(slowRun.AverageNanoseconds / 1000.0 / 1000.0, low: 499, high: 502);
            foreach (var fastRun in fastBenchmarkReport.Runs)
                Assert.InRange(fastRun.AverageNanoseconds / 1000.0 / 1000.0, low: 14, high: 17);
        }
 public void Test()
 {
     var logger = new BenchmarkAccumulationLogger();
     var plugins = BenchmarkPluginBuilder.CreateDefault().AddLogger(logger).Build();
     var reports = new BenchmarkRunner(plugins).Run<SetupAttributeTest>();
     Assert.Contains("// ### Setup called ###" + Environment.NewLine, logger.GetLog());
 }
 public static void Test()
 {
     var logger = new BenchmarkAccumulationLogger();
     var plugins = BenchmarkPluginBuilder.CreateDefault().AddLogger(logger).Build();
     var reports = new BenchmarkRunner(plugins).Run<ParamsTestStaticField>();
     foreach (var param in new[] { 1, 2, 3, 8, 9, 10 })
         Assert.Contains($"// ### New Parameter {param} ###" + Environment.NewLine, logger.GetLog());
     Assert.DoesNotContain($"// ### New Parameter 0 ###" + Environment.NewLine, logger.GetLog());
 }
Exemplo n.º 6
0
 public void Test()
 {
     var logger = new BenchmarkAccumulationLogger();
     var plugins = BenchmarkPluginBuilder.CreateDefault().AddLogger(logger).Build();
     // Run our "Pretend F# test" (see above for more info)
     var reports = new BenchmarkRunner(plugins).Run<BenchmarkSpec.Db>();
     var testLog = logger.GetLog();
     Assert.Contains("// ### F# Benchmark method called ###", testLog);
     Assert.DoesNotContain("No benchmarks found", testLog);
 }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            // This currently doesn't work, because the BenchmarkBaselineDeltaResultExtender() is NEVER wired up!!!!!!
            //new BenchmarkRunner().Run<BenchmarkProgram>();

            var logger = new BenchmarkAccumulationLogger();
            var extender = new BenchmarkBaselineDeltaResultExtender();
            var plugins = BenchmarkPluginBuilder.CreateDefault()
                                .AddLogger(logger)
                                .AddResultExtender(extender)
                                .Build();
            var reports = new BenchmarkRunner(plugins).Run<BenchmarkProgram>();
        }
        public void Test()
        {
            var logger = new BenchmarkAccumulationLogger();
            var sourceDiagnoser = new BenchmarkSourceDiagnoser();
            var plugins = BenchmarkPluginBuilder.CreateDefault()
                                .AddLogger(logger)
                                .AddDiagnoser(sourceDiagnoser)
                                .Build();
            var reports = new BenchmarkRunner(plugins).Run<SourceDiagnoserTest>();

            var testOutput = logger.GetLog();
            Assert.Contains($"Printing Code for Method: {this.GetType().FullName}.DictionaryEnumeration()", testOutput);
            Assert.Contains("PrintAssembly=True", testOutput);
        }
        public void Test()
        {
            var logger = new BenchmarkAccumulationLogger();
            var plugins = BenchmarkPluginBuilder.CreateDefault().AddLogger(logger).Build();
            var reports = new BenchmarkRunner(plugins).Run<BenchmarkModeTests>();
            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 BenchmarkAccumulationLogger();
            var testExporter = new TestBenchmarkExporter();
            var plugins = BenchmarkPluginBuilder.CreateDefault()
                                .AddLogger(logger)
                                .AddExporters(testExporter)
                                .Build();
            var reports = new BenchmarkRunner(plugins).Run(this.GetType()).ToList();

            // Ensure that when the TestBenchmarkExporter() was run, it wasn't passed an instance of "BenchmarkBaselineDeltaResultExtender"
            Assert.False(testExporter.ExportCalled);
            Assert.Null(testExporter.ExportResultExtenders);
            Assert.NotNull(testExporter.ExportToFileResultExtenders);
            Assert.Equal(0, testExporter.ExportToFileResultExtenders.OfType<BenchmarkBaselineDeltaResultExtender>().Count());
            Assert.True(testExporter.ExportToFileCalled);
        }
 public static void Test()
 {
     var logger = new BenchmarkAccumulationLogger();
     var plugins = BenchmarkPluginBuilder.CreateDefault().AddLogger(logger).Build();
     // System.InvalidOperationException : Field "StaticParamField" must be public if it has the [Params(..)] attribute applied to it
     Assert.Throws<InvalidOperationException>(() => new BenchmarkRunner(plugins).Run<ParamsTestStaticPrivateField>());
 }