/// <summary> /// Wraps the test with a stopwatch to monitor the time taken to process the requested tester. /// </summary> /// <param name="tester">The class to do the testing with.</param> /// <param name="numberToTest">The number to use with the test.</param> protected static void IsPrimeTimer(IIsPrime tester, ulong numberToTest) { bool result = false; System.Diagnostics.Debug.WriteLine($"{tester.GetType().Name}"); Console.Write($"{DateTime.Now.ToString()} : {tester.GetType().Name} : "); Stopwatch sw = new Stopwatch(); sw.Restart(); result = tester.CheckIsPrime(numberToTest); sw.Stop(); Console.Write($"Result = {result} : Time Taken : {PrimeNumbers.Model.Utilities.ElaspedTimeFormatter(sw.Elapsed)}"); Console.WriteLine(); }
/// <summary> /// /// </summary> /// <param name="tester"></param> /// <param name="trier"></param> /// <param name="startNumber"></param> /// <param name="endNumber"></param> /// <returns></returns> protected static PrimeDataDto FindPrimesBetweenTimer(IFindPrimesBetween tester, IIsPrime trier, ulong startNumber, ulong endNumber) { PrimeDataDto results = null; System.Diagnostics.Debug.WriteLine($"{tester.GetType().Name} : {trier.GetType().Name} : {startNumber.ToString("#,##0")} - {endNumber.ToString("#,##0")}"); Console.Write($"{DateTime.Now.ToString()} : {tester.GetType().Name} : {trier.GetType().Name} : {startNumber.ToString("#,##0")} - {endNumber.ToString("#,##0")} : "); Stopwatch sw = new Stopwatch(); sw.Restart(); tester.Execute(startNumber, endNumber, trier); sw.Stop(); results = tester.Data; //Console.WriteLine($"{DateTime.Now.ToString()} {Environment.NewLine}{tester.GetType().Name} : {trier.GetType().Name}{Environment.NewLine}{startNumber.ToString("#,##0")} - {endNumber.ToString("#,##0")}{Environment.NewLine} Time Taken : {PrimeNumbers.Model.Utilities.ElaspedTimeFormatter(sw.Elapsed)}{Environment.NewLine}Result : {result.Count.ToString("#,##0")}{Environment.NewLine}"); Console.Write($"Result = {results.PrimeNumbers.Count().ToString("#,##0")} : Time Taken : {PrimeNumbers.Model.Utilities.ElaspedTimeFormatter(sw.Elapsed)}"); Console.WriteLine(); return(results); }
/// <summary> /// /// </summary> /// <param name="findPrimesToTester"></param> /// <param name="isPrimeTester"></param> /// <param name="numberOfPrimesToFind"></param> /// <returns></returns> protected static ICollection <int> FindPrimesToTimer(IFindPrimesTo findPrimesToTester, IIsPrime isPrimeTester, int numberOfPrimesToFind) { ICollection <int> result = new List <int>(); System.Diagnostics.Debug.WriteLine($"{findPrimesToTester.GetType().Name} : {isPrimeTester.GetType().Name}"); Stopwatch sw = new Stopwatch(); sw.Restart(); findPrimesToTester.Execute(numberOfPrimesToFind, isPrimeTester); result = findPrimesToTester.PrimeNumbers; sw.Stop(); Console.WriteLine($"{DateTime.Now.ToString()} : {findPrimesToTester.GetType().Name} : {isPrimeTester.GetType().Name} : Result = {result.Count.ToString("#,##0")} : Time Taken : {PrimeNumbers.Model.Utilities.ElaspedTimeFormatter(sw.Elapsed)}"); return(result); }