Esempio n. 1
0
        /// <summary>
        /// Executes a benchmark with a given map description.
        /// </summary>
        /// <typeparam name="TGenerator"></typeparam>
        /// <typeparam name="TMapDescription"></typeparam>
        /// <typeparam name="TLayout"></typeparam>
        /// <param name="generator">Generator to be used.</param>
        /// <param name="label">Name of a given map description.</param>
        /// <param name="input">Map description to be given to the generator.</param>
        /// <param name="repeats">How many times should te generator run for every given map description</param>
        /// <param name="numberOfLayouts">How many layouts should be generated in every run.</param>
        /// <param name="showCurrentProgress">Whether a current progress should be shown to the console.</param>
        /// <param name="debugWriter">Text writer for debug info. Debug info is not displayed if null.</param>
        /// <returns></returns>
        public BenchmarkResult Execute(IBenchmarkableLayoutGenerator <TMapDescription, TLayout> generator, string label, TMapDescription input, int repeats = 10, int numberOfLayouts = 10, bool showCurrentProgress = true, TextWriter debugWriter = null)
        {
            generator.EnableBenchmark(true);

            var layoutCounts    = new List <int>();
            var iterationCounts = new List <int>();
            var timesFirst      = new List <int>();
            var timesTen        = new List <int>();

            for (var i = 0; i < repeats; i++)
            {
                if (showCurrentProgress)
                {
                    Console.SetCursorPosition(0, Console.CursorTop);
                    Console.Write($" -- Iteration {i + 1}/{repeats}".PadRight(100));
                }

                generator.GetLayouts(input, numberOfLayouts);
                debugWriter?.WriteLine(GetDebugInfo(generator));
                debugWriter?.Flush();

                layoutCounts.Add(generator.LayoutsCount);
                iterationCounts.Add(generator.IterationsCount);
                timesFirst.Add((int)generator.TimeFirst);
                timesTen.Add((int)generator.TimeTotal);
            }

            Console.SetCursorPosition(0, Console.CursorTop);

            return(new BenchmarkResult()
            {
                Name = label,

                LayoutsAvg = layoutCounts.Average(),
                LayoutsMedian = layoutCounts.GetMedian(),

                IterationsAvg = iterationCounts.Average(),
                IterationsMedian = iterationCounts.GetMedian(),

                TimeFirstAvg = timesFirst.Average(),
                TimeFirstMedian = timesFirst.GetMedian(),

                TimeTenAvg = timesTen.Average(),
                TimeTenMedian = timesTen.GetMedian(),
            });
        }
        public BenchmarkResult Execute()
        {
            generator.EnableBenchmark(true);

            var successRates    = new List <int>();
            var iterationCounts = new List <int>();
            var times           = new List <int>();

            for (int i = 0; i < repeats; i++)
            {
                generator.GetLayouts(input, 1);

                successRates.Add(generator.LayoutsCount);
                iterationCounts.Add(generator.IterationsCount);
                times.Add((int)generator.TimeTotal);

                OnPreview?.Invoke(GetResult($"Run {i + 1}/{repeats}", successRates, iterationCounts, times));
            }

            return(GetResult(label, successRates, iterationCounts, times));
        }