Exemplo n.º 1
0
        public Config()
        {
            Add(ConsoleLogger.Default);

            Add(CsvExporter.Default);
            Add(MarkdownExporter.GitHub);
            Add(HtmlExporter.Default);

            var md = new MemoryDiagnoser();

            Add(md);
            Add(new ORMColum());
            Add(TargetMethodColumn.Method);
            Add(new ReturnColum());
            Add(StatisticColumn.Mean);
            //Add(StatisticColumn.StdDev);
            //Add(StatisticColumn.Error);
            Add(new RankColumn(NumeralSystem.Arabic));
            Add(BaselineScaledColumn.Scaled);
            Add(md.GetColumnProvider());

            Add(Job.ShortRun
                .WithLaunchCount(1)
                .WithWarmupCount(2)
                .WithUnrollFactor(Iterations)
                .WithIterationCount(1)
                );
            Set(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest));
            SummaryPerType = false;
        }
Exemplo n.º 2
0
        public void MemoryDiagnoserTracksHeapMemoryAllocation()
        {
            var memoryDiagnoser = new MemoryDiagnoser();
            var config          = CreateConfig(memoryDiagnoser, 50);
            var benchmarks      = BenchmarkConverter.TypeToBenchmarks(typeof(NewVsStackalloc), config);

            var summary = BenchmarkRunner.Run((Benchmark[])benchmarks, config);

            var gcCollectionColumns  = GetColumns <MemoryDiagnoser.GCCollectionColumn>(memoryDiagnoser).ToArray();
            var stackallocBenchmarks = benchmarks.Where(benchmark => benchmark.DisplayInfo.Contains("Stackalloc"));
            var newArrayBenchmarks   = benchmarks.Where(benchmark => benchmark.DisplayInfo.Contains("New"));

            const int gen0Index = 0;

            foreach (var benchmark in stackallocBenchmarks)
            {
                var gen0Collections = gcCollectionColumns[gen0Index].GetValue(summary, benchmark);

                Assert.Equal("-", gen0Collections);
            }

            foreach (var benchmark in newArrayBenchmarks)
            {
                var gen0Str = gcCollectionColumns[gen0Index].GetValue(summary, benchmark);

                AssertParsed(gen0Str, gen0Value => gen0Value > 0);
            }
        }
Exemplo n.º 3
0
        public Config()
        {
            Add(ConsoleLogger.Default);

            Add(CsvExporter.Default);
            Add(MarkdownExporter.GitHub);
            Add(HtmlExporter.Default);

            var md = new MemoryDiagnoser();

            Add(md);
            Add(new ProviderColumn());
            Add(TargetMethodColumn.Method);
            Add(StatisticColumn.Mean);
            Add(BaselineRatioColumn.RatioMean);
            Add(RankColumn.Arabic);

            Add(BenchmarkLogicalGroupRule.ByCategory);

            Add(Job.Dry
                .WithLaunchCount(1)
                .WithWarmupCount(1)
                .WithIterationCount(1)
                .WithGcForce(true)
                .With(InProcessToolchain.Instance)
                );

            Set(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest));

            SummaryPerType = false;
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            var config      = ManualConfig.Create(DefaultConfig.Instance);
            var gcDiagnoser = new MemoryDiagnoser();

            config.Add(gcDiagnoser);

            //BenchmarkRunner.Run<Reflection.Core.PeCoffFileBenchmark>();
            //BenchmarkRunner.Run<Reflection.Core.COFF.StringStreamBenchmark>();
            //BenchmarkRunner.Run<Reflection.AssemblyDefBenchmark>();
            //BenchmarkRunner.Run<Reflection.Syntax.CSharp.ClassFormatterBenchmark>();
            //BenchmarkRunner.Run<Reflection.DisplayNameSignatureBenchmark>();
            BenchmarkRunner.Run <Reflection.Signatures.SignatureBenchmark>();
        }
Exemplo n.º 5
0
        public void AssertZeroAllocations(Type benchmarkType, string benchmarkMethodName, int targetCount)
        {
            var memoryDiagnoser = new MemoryDiagnoser();
            var config          = CreateConfig(memoryDiagnoser, targetCount);
            var benchmarks      = BenchmarkConverter.TypeToBenchmarks(benchmarkType, config);

            var summary = BenchmarkRunner.Run((Benchmark[])benchmarks, config);

            var allocationColumn          = GetColumns <MemoryDiagnoser.AllocationColumn>(memoryDiagnoser).Single();
            var allocateNothingBenchmarks = benchmarks.Where(benchmark => benchmark.DisplayInfo.Contains(benchmarkMethodName));

            foreach (var benchmark in allocateNothingBenchmarks)
            {
                var allocations = allocationColumn.GetValue(summary, benchmark);

                AssertParsed(allocations, allocatedBytes => allocatedBytes == 0);
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            if (true)
            {
                var config      = ManualConfig.Create(DefaultConfig.Instance);
                var gcDiagnoser = new MemoryDiagnoser();
                config.Add(new Job
                {
                    Mode          = Mode.SingleRun,
                    LaunchCount   = 2,
                    WarmupCount   = 2,
                    IterationTime = 1024,
                    TargetCount   = 10
                });
                config.Add(gcDiagnoser);

                //var  config = DefaultConfig.Instance;
                //BenchmarkRunner.Run<BenchMinifier>(config);
                BenchmarkRunner.Run <BenchParser>(config);
            }
#pragma warning disable CS0162 // Unreachable code detected
            else
            {
                var program = new BenchMinifier();

                var clock = Stopwatch.StartNew();

                GC.Collect(2, GCCollectionMode.Forced, true);

                var gc0 = GC.CollectionCount(0);
                var gc1 = GC.CollectionCount(1);
                var gc2 = GC.CollectionCount(2);

                program.BenchNUglify();

                clock.Stop();
                Console.WriteLine($" => time: {(double)clock.ElapsedMilliseconds / 1}ms (total {clock.ElapsedMilliseconds}ms)");
                DumpGC(gc0, gc1, gc2);
            }
#pragma warning restore CS0162 // Unreachable code detected
        }
 private static T[] GetColumns <T>(MemoryDiagnoser memoryDiagnoser, Summary summary)
 => memoryDiagnoser.GetColumnProvider().GetColumns(summary).OfType <T>().ToArray();
Exemplo n.º 8
0
 private static T[] GetColumns <T>(MemoryDiagnoser memoryDiagnoser)
 => memoryDiagnoser.GetColumnProvider().GetColumns(null).OfType <T>().ToArray();