aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-12-17 05:26:44 +0200
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-12-17 05:26:44 +0200
commitf32a4fdbaaa4ef966d27c7d2727d81bf65aabb61 (patch)
tree07f4d18cb3033e3bef1309af3f447a2bab63195c /Software/Visual_Studio/StubsUtils/Tango.StubsUtils.PerformanceTest.CLI/Program.cs
parenta309970822fdc61357db07c32fd67b15d1c497f0 (diff)
downloadTango-f32a4fdbaaa4ef966d27c7d2727d81bf65aabb61.tar.gz
Tango-f32a4fdbaaa4ef966d27c7d2727d81bf65aabb61.zip
StubsUtils
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.cs90
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();
+ }
+ }
+}