Ejemplo n.º 1
0
            public Config()
            {
                //Our configuration is based on the DebugInProcessConfig, but adds one more column to it
                var x = new BenchmarkDotNet.Configs.DebugInProcessConfig();

                //So basically "Copy" the DebugInProcessConfig
                Options       = BenchmarkDotNet.Configs.ConfigOptions.DisableOptimizationsValidator | BenchmarkDotNet.Configs.ConfigOptions.KeepBenchmarkFiles;
                Orderer       = x.Orderer;
                SummaryStyle  = x.SummaryStyle;
                ArtifactsPath = x.ArtifactsPath;

                if (BenchmarkDotNet.Jobs.Job.Default == x.GetJobs().First())
                {
                    Console.WriteLine();
                }

                Add(x.GetJobs().First());
                Add(x.GetLoggers().First());

                foreach (var colProvider in x.GetColumnProviders())
                {
                    Add(colProvider);
                }

                //And add one column for mean area of the packing result, because only measuring time would be meaningless for packing ...
                Add(new BenchmarkDotNet.Columns.TagColumn("Mean area", (k) =>
                {
                    //Benchmarks just finished
                    //So read the file and obtain the mean return values of the benchmark methods
                    if (results == null)
                    {
                        //Results are stored in form: Name of the test method : Queue of average packing result areas
                        //The reason for stack is that a method with same methodname could by called for different values of N
                        //In the output these are sorted increasingly so it is safe to do it via Queue
                        results = new Dictionary <string, Queue <string> >();
                        using (var sr = new StreamReader("results.txt"))
                        {
                            string line = "";
                            while ((line = sr.ReadLine()) != null)
                            {
                                var chunks = line.Split(";");
                                if (chunks.Length >= 2)
                                {
                                    if (!results.ContainsKey(chunks[0]))
                                    {
                                        results[chunks[0]] = new Queue <string>();
                                    }
                                    results[chunks[0]].Enqueue(chunks[1]);
                                }
                                //otherwise Skip
                            }
                        }
                        //Delete the file with results
                        File.Delete("results.txt");
                    }
                    return(results[k].Dequeue());
                }));
            }
Ejemplo n.º 2
0
        // https://benchmarkdotnet.org/articles/guides/getting-started.html

        public static void Main(string[] args)
        {
            #if DEBUG
            var cfg = new BenchmarkDotNet.Configs.DebugInProcessConfig();
            #else
            var cfg = BenchmarkDotNet.Configs.DefaultConfig.Instance;
            #endif

            var summary = BenchmarkSwitcher
                          .FromAssembly(typeof(Program).Assembly)
                          .Run(args);
        }