private List <BenchmarkPartialResult> DoDiskBenchmark(BigTest testSuite, string driverName) { List <BenchmarkPartialResult> result = new List <BenchmarkPartialResult>(); try { using (testSuite) { base.WriteMessage(string.Format("Test file: {0}, Size: {1:0.00}Gb\n\n Press ESC to break", testSuite.FilePath, (double)testSuite.FileSize / 1024 / 1024 / 1024)); string currentTest = null; const int curCursor = 40; var breakTest = false; testSuite.StatusUpdate += (sender, e) => { if (breakTest) { return; } //if (e.Status == TestStatus.NotStarted) return; if ((sender as Test).DisplayName != currentTest) { currentTest = (sender as Test).DisplayName; TryWriteConsole(string.Format("\n{0}/{1} {2}", testSuite.CompletedTests + 1, testSuite.TotalTests, (sender as Test).DisplayName)); } ClearLine(curCursor); if (e.Status != TestStatus.Completed) { Console.ForegroundColor = ConsoleColor.DarkGray; switch (e.Status) { case TestStatus.Started: TryWriteConsole(string.Format("Started")); break; case TestStatus.InitMemBuffer: TryWriteConsole(string.Format("Initializing test data in RAM...")); break; case TestStatus.PurgingMemCache: TryWriteConsole(string.Format("Purging file cache in RAM...")); break; case TestStatus.WarmigUp: TryWriteConsole(string.Format("Warming up...")); break; case TestStatus.Interrupted: TryWriteConsole(string.Format("Test interrupted")); break; case TestStatus.Running: TryWriteConsole(string.Format("{0}% {2} {1:0.00} MB/s", e.ProgressPercent, e.RecentResult, GetNextAnimation())); break; } // Console.ResetColor(); } else if ((e.Status == TestStatus.Completed) && (e.Results != null)) { TryWriteConsole(string.Format( string.Format("Avg: {1:0.00}{0}\t", unit, e.Results.AvgThroughput)) ); //Console.ForegroundColor = ConsoleColor.DarkGray; TryWriteConsole(string.Format( string.Format(" Min÷Max: {1:0.00} ÷ {2:0.00}, Time: {3}m{4:00}s", unit, e.Results.Min, e.Results.Max, e.ElapsedMs / 1000 / 60, e.ElapsedMs / 1000 % 60)) ); //Console.ResetColor(); } /*if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) * { * base.WriteMessage(" Stopping..."); * breakTest = true; * testSuite.Break(); * }*/ try { ShowCounters(testSuite); } catch (Exception ex) { //TODO: IMPLEMENTAR EXCEPTION System.Diagnostics.Debugger.Log(0, "", ex.ToString()); } }; var results = testSuite.Execute(); if (!breakTest) { base.WriteMessage(string.Format("\n\nWrite Score*:\t {0:0.00} MB/s", testSuite.WriteScore)); base.WriteMessage(string.Format("Read Score*:\t {0:0.00} MB/s", testSuite.ReadScore)); Console.ForegroundColor = ConsoleColor.DarkGray; base.WriteMessage("*Calculation: average throughput with 80% read/written seqentialy and 20% randomly"); Console.ResetColor(); base.WriteMessage("\nTest file deleted."); result.Add(new BenchmarkPartialResult() { Description = $"LOCAL STORAGE SPEED - WRITE [{driverName}]", MetricScale = MetricScaleType.MEGABYTE, ResultType = BenchmarkResultType.UPLOAD_SPEED, Score = Math.Round(testSuite.WriteScore, 2) }); result.Add(new BenchmarkPartialResult() { Description = $"LOCAL STORAGE SPEED - READ [{driverName}]", MetricScale = MetricScaleType.MEGABYTE, ResultType = BenchmarkResultType.UPLOAD_SPEED, Score = Math.Round(testSuite.ReadScore, 2) }); //result.Score = Math.Round((testSuite.WriteScore + testSuite.ReadScore) / 2,2); //result.StepsDetails.Add(string.Format("Write Score*:\t {0:0.00} MB/s", testSuite.WriteScore) + " | " + string.Format("Read Score*:\t {0:0.00} MB/s", testSuite.ReadScore)); //base.WriteMessage("\nTest file deleted. Saving results to CSV files in folder: " + testSuite.ResultsFolderPath); //testSuite.ExportToCsv(testSuite.ResultsFolderPath, true); } } } catch (Exception ex) { base.WriteMessage("\nProgram interupted due to unexpected error:"); base.WriteMessage("\t" + ex.GetType() + " " + ex.Message); base.WriteMessage(ex.StackTrace); } /*if (!RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX)) * { * base.WriteMessage("\nPress any key to quit"); * Console.ReadKey(); * }*/ return(result); }
static void Main(string[] args) { try { Console.WriteLine("CPDT_Console - STORAGE SPEED TEST\n"); Console.ForegroundColor = ConsoleColor.DarkGray; //Console.WriteLine("Total RAM: {0:0.00}Gb, Available RAM: {1:0.00}Gb\n", (double)RamDiskUtil.TotalRam / 1024 / 1024 / 1024, (double)RamDiskUtil.FreeRam / 1024 / 1024 / 1024); WriteLineWordWrap("The test uses standrd OS's file API (WinAPI on Windows and POSIX on Mac/Linux) to measure the speed of transfers between storage device and system memory.\nWrite buffering and mem cahce are disabled\n"); Console.ResetColor(); const long fileSize = 1024 * 1024 * 1024; var drivePath = PickDrive(fileSize); if (drivePath == null) { return; } var testSuite = new BigTest(drivePath, fileSize, false); using (testSuite) { Console.WriteLine("Test file: {0}, Size: {1:0.00}Gb\n\n Press ESC to break", testSuite.FilePath, (double)testSuite.FileSize / 1024 / 1024 / 1024); string currentTest = null; const int curCursor = 40; var breakTest = false; testSuite.StatusUpdate += (sender, e) => { if (breakTest) { return; } if (e.Status == TestStatus.NotStarted) { return; } if ((sender as Test).DisplayName != currentTest) { currentTest = (sender as Test).DisplayName; Console.Write("\n{0}/{1} {2}", testSuite.CompletedTests + 1, testSuite.TotalTests, (sender as Test).DisplayName); } ClearLine(curCursor); if (e.Status != TestStatus.Completed) { Console.ForegroundColor = ConsoleColor.DarkGray; switch (e.Status) { case TestStatus.Started: Console.Write("Started"); break; case TestStatus.InitMemBuffer: Console.Write("Initializing test data in RAM..."); break; case TestStatus.PurgingMemCache: Console.Write("Purging file cache in RAM..."); break; case TestStatus.WarmigUp: Console.Write("Warming up..."); break; case TestStatus.Interrupted: Console.Write("Test interrupted"); break; case TestStatus.Running: Console.Write("{0}% {2} {1:0.00} MB/s", e.ProgressPercent, e.RecentResult, GetNextAnimation()); break; } Console.ResetColor(); } else if ((e.Status == TestStatus.Completed) && (e.Results != null)) { Console.Write( string.Format("Avg: {1:0.00}{0}\t", unit, e.Results.AvgThroughput) ); Console.ForegroundColor = ConsoleColor.DarkGray; Console.Write( string.Format(" Min÷Max: {1:0.00} ÷ {2:0.00}, Time: {3}m{4:00}s", unit, e.Results.Min, e.Results.Max, e.ElapsedMs / 1000 / 60, e.ElapsedMs / 1000 % 60) ); Console.ResetColor(); } if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.Escape) { Console.WriteLine(" Stopping..."); breakTest = true; testSuite.Break(); } ShowCounters(testSuite); }; var results = testSuite.Execute(); if (!breakTest) { Console.WriteLine("\n\nWrite Score*:\t {0:0.00} MB/s", testSuite.WriteScore); Console.WriteLine("Read Score*:\t {0:0.00} MB/s", testSuite.ReadScore); Console.ForegroundColor = ConsoleColor.DarkGray; Console.WriteLine("*Calculation: average throughput with 80% read/written seqentialy and 20% randomly"); Console.ResetColor(); Console.WriteLine("\nTest file deleted."); //Console.WriteLine("\nTest file deleted. Saving results to CSV files in folder: " + testSuite.ResultsFolderPath); //testSuite.ExportToCsv(testSuite.ResultsFolderPath, true); } } } catch (Exception ex) { Console.WriteLine("\nProgram interupted due to unexpected error:"); Console.WriteLine("\t" + ex.GetType() + " " + ex.Message); Console.WriteLine(ex.StackTrace); } if (!RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX)) { Console.WriteLine("\nPress any key to quit"); Console.ReadKey(); } }