forked from DigDes/SoapCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (99 loc) · 2.71 KB
/
Program.cs
File metadata and controls
107 lines (99 loc) · 2.71 KB
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
using System;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using System.Threading.Tasks;
using System.Threading;
using Microsoft.AspNetCore.TestHost;
using System.Net.Http;
using System.Net;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Diagnosers;
using Microsoft.Extensions.Logging;
using BenchmarkDotNet.Jobs;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace SoapCore.Benchmark
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net80, baseline: true, iterationCount: 20)]
//[SimpleJob(RuntimeMoniker.NetCoreApp31, iterationCount: 20)]
public class EchoBench
{
// 0 measures overhead of creating host
[Params(100)]
public int LoopNum;
static readonly string EchoContent = @"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
<soap:Body>
<Echo xmlns=""http://example.org/PingService""><str>abc</str></Echo>
</soap:Body>
</soap:Envelope>
";
static TestServer CreateTestHost()
{
var builder = WebHost.CreateDefaultBuilder()
.ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Critical))
.UseStartup<Startup>();
return new TestServer(builder);
}
TestServer m_Host;
[GlobalSetup]
public void Setup()
{
m_Host = CreateTestHost();
}
[GlobalCleanup]
public void Cleanup()
{
m_Host.Dispose();
}
[Benchmark]
public async Task EmptyTask()
{
for (int i = 0; i < LoopNum; i++)
{
using var content = new StringContent(EchoContent, Encoding.UTF8, "text/xml");
using var res = await m_Host.CreateRequest("/")
.AddHeader("SOAPAction", "http://example.org/PingService/Echo")
.And(msg =>
{
msg.Content = content;
}).PostAsync().ConfigureAwait(false);
res.EnsureSuccessStatusCode();
}
}
[Benchmark]
public async Task Echo()
{
for (int i = 0; i < LoopNum; i++)
{
using var content = new StringContent(EchoContent, Encoding.UTF8, "text/xml");
using var res = await m_Host.CreateRequest("/TestService.asmx")
.AddHeader("SOAPAction", "http://example.org/PingService/Echo")
.And(msg =>
{
msg.Content = content;
}).PostAsync().ConfigureAwait(false);
res.EnsureSuccessStatusCode();
}
}
}
class Program
{
static async Task Main()
{
BenchmarkRunner.Run<EchoBench>();
//var eb = new EchoBench();
//eb.Setup();
//eb.LoopNum = 100_000;
//Console.WriteLine("Klicka");
//Console.ReadKey();
//Console.WriteLine("Running...");
//await eb.Echo();
//Console.WriteLine("Klicka igen");
//Console.ReadKey();
//eb.Cleanup();
}
}
}