protected static void SavePrimesTimer(ISavePrimes tester, PrimeDataDto data) { Console.Write($"{DateTime.Now.ToString()} : {tester.GetType().Name} : "); string fileName = string.Format("../saves/{0}_{1}_{2}-{3}.txt", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"), tester.GetType().Name, data.StartNumber, data.EndNumber); Stopwatch sw = new Stopwatch(); sw.Restart(); tester.SavePrimes(fileName, data); sw.Stop(); System.IO.FileInfo f = new System.IO.FileInfo(fileName); Console.Write($"Size : {Utilities.CalculateFileSize(f.Length)} : Speed : {Utilities.CalculateTransferSpeed(f.Length, sw.Elapsed.TotalSeconds)} : Time Taken : {PrimeNumbers.Model.Utilities.ElaspedTimeFormatter(sw.Elapsed)}"); Console.WriteLine(); }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <param name="allowedVersionNumbers"></param> protected static void TestSavePerformance(PrimeDataDto data, int[] allowedVersionNumbers = null) { Type[] findPrimesBetweenTypes = PerformanceTests.GetTestingTypes("PrimeNumbers.Model", "PrimeDataV", allowedVersionNumbers); if ((findPrimesBetweenTypes != null) && (findPrimesBetweenTypes.Any())) { Console.WriteLine($"SavingPrimes Testing with {data.StartNumber.ToString("#,##0")} - {data.EndNumber.ToString("#,##0")}"); foreach (Type type in findPrimesBetweenTypes) { ISavePrimes savePrimesTester = (ISavePrimes)Activator.CreateInstance(type); PerformanceTests.SavePrimesTimer(savePrimesTester, data); } } else { Console.WriteLine("No FindPrimesBetween Classes found to test with"); } Console.WriteLine(); }
/// <summary> /// /// </summary> /// <param name="startNumber"></param> /// <param name="endNumber"></param> /// <param name="primeChecker"></param> /// <param name="primeFinder"></param> /// <param name="primeFileManagement"></param> public FindPrimesBetweenGenerator(ulong startNumber, ulong endNumber, IIsPrime primeChecker, IFindPrimesBetween primeFinder, ISavePrimes primeFileManagement) : base(startNumber, endNumber) { if (primeChecker == null) { throw new ArgumentNullException("primeChecker"); } if (primeFinder == null) { throw new ArgumentNullException("primeFinder"); } if (primeFileManagement == null) { throw new ArgumentNullException("primeFileManagement"); } this.PrimeChecker = primeChecker; this.PrimeFinder = primeFinder; this.PrimeFileSaver = primeFileManagement; }