private static void RunCalculation(BaseIrrational selectedClass) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); decimal result = selectedClass.GetSequence().GetAwaiter().GetResult(); stopwatch.Stop(); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" ".Repeat(20) + "-".Repeat(50)); Console.WriteLine(" ".Repeat(20) + selectedClass.Name + "-" + selectedClass.Description); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"{" ".Repeat(20)}Result: {result}"); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"{" ".Repeat(20)}Time took: {stopwatch.ElapsedMilliseconds}ms"); Console.WriteLine($"{" ".Repeat(20)}Difference from control is: {string.Format("{0:E2}", result - selectedClass.ControlValue)}"); }
internal static List <BaseIrrational> GetInput(List <BaseIrrational> instances, out string error) { int i = 0; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" ".Repeat(20) + "-".Repeat(25)); instances.ForEach((inst) => { Console.ForegroundColor = ConsoleColor.Cyan; Console.Write($" ".Repeat(20) + $"#{i++} - {inst.Name}"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(" - " + inst.Description); }); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" ".Repeat(20) + "-".Repeat(25)); Console.Write(" ".Repeat(20) + "Your Selection #: "); // we could have multiple entries so we handle that here: string entry = Console.ReadLine(); string[] entries = entry.Split(','); List <string> errors = entries.Select(x => ErrorCheck(x, instances.Count)).Where(y => y != null)?.ToList(); if (errors != null && errors.Count > 0) { error = errors.First(); return(null); } Console.Write($"{" ".Repeat(20)}Number of tasks to spawn (default: processor/thread count: {Environment.ProcessorCount}): #"); string taskNumberStr = Console.ReadLine(); if ((taskNumberStr ?? "") == "") { taskNumberStr = Environment.ProcessorCount.ToString(); } int taskNumber = 0; Console.Write($"{" ".Repeat(20)}Number of calculations per task (default: 10000): #"); string calcNumberStr = Console.ReadLine(); if ((calcNumberStr ?? "") == "") { calcNumberStr = "10000"; } int calcNumber = 0; if (!int.TryParse(taskNumberStr, out taskNumber) || taskNumber < 1 || !int.TryParse(calcNumberStr, out calcNumber) || calcNumber < 1) { error = "You must enter an integer value greater than 0 for # of tasks and number of calculations"; return(null); } List <BaseIrrational> selectedClasses = entries.Select(x => { BaseIrrational instance = instances[Convert.ToInt32(x)]; instance.TaskIterations = taskNumber; instance.InternalIterations = calcNumber; return(instance); }).ToList(); error = null; return(selectedClasses); }