public BenchmarkJob(
     IBenchmarkableLayoutGenerator <TMapDescription, TLayout> generator, string label,
     TMapDescription input, int repeats = 10)
 {
     this.generator = generator;
     this.label     = label;
     this.input     = input;
     this.repeats   = repeats;
 }
Пример #2
0
        private string GetDebugInfo(IBenchmarkableLayoutGenerator <TMapDescription, TLayout> generator)
        {
            var builder = new StringBuilder();

            builder.AppendLine($"Layouts: {generator.LayoutsCount}, Iteration: {generator.IterationsCount}");
            builder.AppendLine();
            // builder.AppendLine(generator.GetPlannerLog()); TODO: fix

            return(builder.ToString());
        }
		/// <summary>
		/// Executes a benchmark with a list of map descriptions.
		/// </summary>
		/// <typeparam name="TMapDescription"></typeparam>
		/// <typeparam name="TLayout"></typeparam>
		/// <param name="generator">Generator to be used</param>
		/// <param name="label">Label of the run. Will be used in a header of the result.</param>
		/// <param name="mapDescriptions">Map descriptions to be given to the generator. First item of the tuple represents a name of the map description.</param>
		/// <param name="repeats">How many times should te generator run for every given map description</param>
		/// <param name="filename"></param>
		public void Execute(IBenchmarkableLayoutGenerator<TMapDescription, TLayout> generator, string label, List<Tuple<string, TMapDescription>> mapDescriptions, int repeats = 10, string filename = null)
		{
			var benchmarkJobs = new List<BenchmarkJob<TMapDescription, TLayout>>();
			var benchmark = new BenchmarkUtils.Benchmark<BenchmarkJob<TMapDescription, TLayout>, BenchmarkResult>();
			benchmark.SetConsoleOutput(true);
			benchmark.AddFileOutput(namingConvention: NamingConvention.FixedName, filename: filename);

			foreach (var mapDescriptionInfo in mapDescriptions)
			{
				benchmarkJobs.Add(new BenchmarkJob<TMapDescription, TLayout>(generator, mapDescriptionInfo.Item1, mapDescriptionInfo.Item2, repeats));
			}

			benchmark.Run(benchmarkJobs.ToArray(), label + $" ({repeats} repeats)");
		}
Пример #4
0
        /// <summary>
        /// Executes a benchmark with a list of map descriptions.
        /// </summary>
        /// <typeparam name="TGenerator"></typeparam>
        /// <typeparam name="TMapDescription"></typeparam>
        /// <typeparam name="TLayout"></typeparam>
        /// <param name="generator">Generator to be used</param>
        /// <param name="label">Label of the run. Will be used in a header of the result.</param>
        /// <param name="mapDescriptions">Map descriptions to be given to the generator. First item of the tuple represents a name of the map description.</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="writer">Will be used in conjuction with Console.Out if not null.</param>
        /// <param name="debugWriter">Text writer for debug info. Debug info is not displayed if null.</param>
        public void Execute(IBenchmarkableLayoutGenerator <TMapDescription, TLayout> generator, string label, List <Tuple <string, TMapDescription> > mapDescriptions, int repeats = 10, int numberOfLayouts = 10, TextWriter writer = null, TextWriter debugWriter = null)
        {
            var results = mapDescriptions.Select(x => Execute(generator, x.Item1, x.Item2, repeats, numberOfLayouts, debugWriter: debugWriter));

            WriteLine(GetOutputHeader(label, repeats), writer);

            foreach (var result in results)
            {
                WriteLine(GetOutput(result), writer);
                writer?.Flush();
            }

            WriteLine(GetOutputFooter(), writer);
        }
Пример #5
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(),
            });
        }
 protected void PrintGeneratorStats(IBenchmarkableLayoutGenerator <MapDescription <TRoom>, IMapLayout <TRoom> > generator)
 {
     Debug.Log($"Layout generated in {generator.TimeFirst / 1000f:F} seconds");
     Debug.Log($"{generator.IterationsCount} iterations needed, {(generator.IterationsCount / (generator.TimeFirst / 1000d)):0} iterations per second");
 }