Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
81 lines (69 loc) · 2.83 KB

File metadata and controls

81 lines (69 loc) · 2.83 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AustinHarris.JsonRpc;
using System.Threading;
using System.Diagnostics;
using System.Threading.Tasks;
namespace TestServer_Console
{
class Program
{
static object[] services = new object[] {
new CalculatorService()
};
static void Main(string[] args)
{
PrintOptions();
for (string line = Console.ReadLine(); line != "q"; line = Console.ReadLine())
{
if (string.IsNullOrWhiteSpace(line))
Benchmark();
else if (line.StartsWith("c", StringComparison.CurrentCultureIgnoreCase))
ConsoleInput();
PrintOptions();
}
}
private static void PrintOptions()
{
Console.WriteLine("Hit Enter to run benchmark");
Console.WriteLine("'c' to start reading console input");
Console.WriteLine("'q' to quit");
}
private static void ConsoleInput()
{
for (string line = Console.ReadLine(); !string.IsNullOrEmpty(line); line = Console.ReadLine())
{
JsonRpcProcessor.Process(line).ContinueWith(response => Console.WriteLine( response.Result ));
}
}
private static volatile int ctr;
private static void Benchmark()
{
Console.WriteLine("Starting benchmark");
var cnt = 50;
var iterations = 7;
for (int iteration = 1; iteration <= iterations; iteration++)
{
cnt *= iteration;
ctr = 0;
Task<string>[] tasks = new Task<string>[cnt];
var sw = Stopwatch.StartNew();
var sessionid = Handler.DefaultSessionId();
for (int i = 0; i < cnt; i+=5)
{
tasks[i] = JsonRpcProcessor.Process(sessionid, "{'method':'add','params':[1,2],'id':1}");
tasks[i+1] = JsonRpcProcessor.Process(sessionid, "{'method':'addInt','params':[1,7],'id':2}");
tasks[i+2] = JsonRpcProcessor.Process(sessionid, "{'method':'NullableFloatToNullableFloat','params':[1.23],'id':3}");
tasks[i+3] = JsonRpcProcessor.Process(sessionid, "{'method':'Test2','params':[3.456],'id':4}");
tasks[i+4] = JsonRpcProcessor.Process(sessionid, "{'method':'StringMe','params':['Foo'],'id':5}");
}
Task.WaitAll(tasks);
sw.Stop();
Console.WriteLine("processed {0:N0} rpc in \t {1:N0}ms for \t {2:N} rpc/sec", cnt, sw.ElapsedMilliseconds, (double)cnt * 1000d / sw.ElapsedMilliseconds);
}
Console.WriteLine("Finished benchmark...");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.