diff options
Diffstat (limited to 'Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs')
| -rw-r--r-- | Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs new file mode 100644 index 000000000..16492a276 --- /dev/null +++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace Tango.StubsUtils.PerformanceTest.CLI +{ + class Program + { + private const int ROUNDS = 10000; + + static void Main(string[] args) + { + List<double> durations = new List<double>(); + + Process process = new Process(); + process.StartInfo.FileName = "tangostub_s.exe"; + process.StartInfo.CreateNoWindow = true; + process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.RedirectStandardInput = true; + process.StartInfo.UseShellExecute = false; + process.Start(); + process.PriorityClass = ProcessPriorityClass.RealTime; + + process.StandardOutput.ReadLine(); //Read the first welcome line... + + Stopwatch watch = new Stopwatch(); + + for (int i = 0; i < ROUNDS; i++) + { + watch.Restart(); + + process.StandardInput.WriteLine("calculate 10 15"); + StringBuilder builder = new StringBuilder(); + + char[] buffer = new char[1]; + + while (process.StandardOutput.Read(buffer, 0, 1) > 0) + { + char c = buffer[0]; + + if (c == '\r') + { + process.StandardOutput.Read(); + break; + } + else if (c == '>') + { + process.StandardOutput.Read(); + } + else + { + builder.Append(buffer[0]); + } + } + + String response = builder.ToString(); + + if (response.StartsWith("Status: Error")) + { + OnError(response); + return; + } + + durations.Add(watch.ElapsedMilliseconds); + + Console.SetCursorPosition(0, 0); + Console.Write($"Performance test: {i + 1}/{ROUNDS}, Avg: {Math.Round(durations.Average(), 2)} ms "); + } + + Console.WriteLine(); + Console.WriteLine(); + Console.WriteLine("Completed."); + Console.ReadLine(); + } + + private static void OnError(String error) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(error); + Console.ForegroundColor = ConsoleColor.Gray; + Console.ReadLine(); + } + } +} |
