blob: ff172737aec4c5803893d39f3a3d39c080088944 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
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 = 100;
private const int DELAY = 0;
static void Main(string[] args)
{
PerformanceTestStandard();
Console.WriteLine();
PerformanceTestSession();
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Completed.");
Console.ReadLine();
}
private static void PerformanceTestStandard()
{
List<double> durations = new List<double>();
Stopwatch watch = new Stopwatch();
for (int i = 0; i < ROUNDS; i++)
{
watch.Restart();
Process process = new Process();
process.StartInfo.FileName = "tangostub.exe";
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.Arguments = "calculate 10 15";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();
process.WaitForExit();
String response = process.StandardOutput.ReadToEnd();
if (!response.StartsWith("Status: OK"))
{
OnError(response);
return;
}
if (DELAY > 0)
{
Thread.Sleep(DELAY);
}
durations.Add(watch.ElapsedMilliseconds);
Console.SetCursorPosition(0, 0);
Console.Write($"Performance Test (Standard): {i + 1}/{ROUNDS}, Avg: {Math.Round(durations.Average(), 2)} ms ");
}
}
private static void PerformanceTestSession()
{
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.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: OK"))
{
OnError(response);
return;
}
if (DELAY > 0)
{
Thread.Sleep(DELAY);
}
durations.Add(watch.ElapsedMilliseconds);
Console.SetCursorPosition(0, 1);
Console.Write($"Performance Test (Session) : {i + 1}/{ROUNDS}, Avg: {Math.Round(durations.Average(), 2)} ms ");
}
}
private static void OnError(String error)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(error);
Console.ForegroundColor = ConsoleColor.Gray;
Console.ReadLine();
}
}
}
|