baseline: OpenMU upstream b5a0961 (fresh source)

This commit is contained in:
Acentech Dev
2026-07-14 19:00:35 +03:00
parent 450402e47d
commit 36fc125d5c
11968 changed files with 748705 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
// <copyright file="EncryptionBenchmarks.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.Network.Benchmarks;
using System.Buffers;
using System.IO.Pipelines;
using MUnique.OpenMU.Network.SimpleModulus;
using MUnique.OpenMU.Network.Xor;
/// <summary>
/// Benchmarks for the simple modulus encryption.
/// </summary>
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[MemoryDiagnoser]
[InvocationCount(100)]
public class EncryptionBenchmarks
{
/// <summary>
/// The packet count for each benchmark run.
/// </summary>
private const int PacketCount = 100000;
/// <summary>
/// That's a 185 bytes unencrypted C3 packet. Encrypted it takes 255 bytes.
/// </summary>
private readonly byte[] _c3Packet = Convert.FromBase64String("w7kxFgK8hYpGGLgdXe7ZpTZViB+r3sRI3YSqZs7/Mh5Vmh2mXqs+3dqkvURmXrL57ASs+FkJz/236Tl9ER67R+WZyMLRMkeLF6tEBiB/4X7SsXrKUznES8of73RxwMy76HZezJbvJ7m9IOGuxcjcNwe6q1+k8fOs1Hz3sULSGlbfiB6qIBXo4onADTNYFoYCQrdtthVsF/aDsvcZ93V36gaKzzyqMhby0sjV4+TAU7719W6LZWNAcnA=");
private readonly byte[] _c1Packet = Convert.FromBase64String("wf8AudHEjjSP53H6Rkp3oXj7B9z+rVDR2f0Is4bvsIsUL3RM/aTDB2FX9YG3Hkboy1Z1JThot558MeDTvNuunzfl5RbWK6TTOP97prjPGbq3IOcweopTq3fVz8vD8EuFqVVJ0jgvEZ+xoe047RHmrRgmG5zzfSWtkTmeAVzZD0i09f1jhUeBiA5HfticGr5m7iGzndSvkSwvm0D/kRBD15GlhPgTgyfQpJONrP5NEHd7NxI6JnJzBWPQM+kHgvb+BKdH95bFUmv54vlBIeUt4ovIg1r9CLEfMX+UQk89yCKcj6dXBRjgteSmQUN5MuN9o1FePv6cAPv2KMUXMBAc");
/// <summary>
/// Benchmarks the performance of the <see cref="SimpleModulusEncryptionAsync"/>.
/// </summary>
/// <returns>The value task.</returns>
[Benchmark]
public async ValueTask SimpleModulusEncryptionAsync()
{
var pipe = new Pipe();
var pipelinedEncryptor = new PipelinedSimpleModulusEncryptor(pipe.Writer);
var readBuffer = new byte[256];
for (int i = 0; i < PacketCount; i++)
{
await pipelinedEncryptor.Writer.WriteAsync(this._c3Packet).ConfigureAwait(false);
await pipelinedEncryptor.Writer.FlushAsync().ConfigureAwait(false);
var readResult = await pipe.Reader.ReadAsync().ConfigureAwait(false);
readResult.Buffer.CopyTo(readBuffer);
//// In the server, I would process the readBuffer here
pipe.Reader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End);
}
await pipelinedEncryptor.Writer.CompleteAsync().ConfigureAwait(false);
}
/// <summary>
/// Benchmarks the performance of the <see cref="MUnique.OpenMU.Network.Xor.PipelinedXor32Encryptor"/>.
/// </summary>
/// <returns>The value task.</returns>
[Benchmark]
public async ValueTask Xor32EncryptionAsync()
{
var pipe = new Pipe();
var pipelinedEncryptor = new PipelinedXor32Encryptor(pipe.Writer);
var readBuffer = new byte[256];
for (int i = 0; i < PacketCount; i++)
{
await pipelinedEncryptor.Writer.WriteAsync(this._c1Packet).ConfigureAwait(false);
await pipelinedEncryptor.Writer.FlushAsync().ConfigureAwait(false);
var readResult = await pipe.Reader.ReadAsync().ConfigureAwait(false);
readResult.Buffer.CopyTo(readBuffer);
//// In the client/server, I would process the readBuffer here
pipe.Reader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End);
}
await pipelinedEncryptor.Writer.CompleteAsync().ConfigureAwait(false);
}
}

View File

@@ -0,0 +1,45 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable;CS4014;VSTHRD110;VSTHRD100</WarningsAsErrors>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ApplicationIcon />
<OutputType>Exe</OutputType>
<StartupObject />
<AssemblyName>MUnique.OpenMU.Network.Benchmarks</AssemblyName>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>bin\Debug\MUnique.OpenMU.Network.Benchmarks.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>bin\Release\MUnique.OpenMU.Network.Benchmarks.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\..\src\SharedAssemblyInfo.cs" Link="Properties\SharedAssemblyInfo.cs" />
<Compile Include="..\..\src\SharedGlobalUsings.cs" Link="SharedGlobalUsings.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\.editorconfig" Link=".editorconfig" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\src\stylecop.json" Link="stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="Nito.AsyncEx.Coordination" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Network\MUnique.OpenMU.Network.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2047
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MUnique.OpenMU.Network.Benchmarks", "MUnique.OpenMU.Network.Benchmarks.csproj", "{CB2197B1-D4D1-42CD-88B8-0BDEA7C83040}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CB2197B1-D4D1-42CD-88B8-0BDEA7C83040}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB2197B1-D4D1-42CD-88B8-0BDEA7C83040}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB2197B1-D4D1-42CD-88B8-0BDEA7C83040}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB2197B1-D4D1-42CD-88B8-0BDEA7C83040}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B2012905-0E9A-4059-9E4D-AD78A91273F1}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,70 @@
// <copyright file="PacketSending.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
using Nito.AsyncEx;
namespace MUnique.OpenMU.Network.Benchmarks;
using System.Threading;
using Microsoft.Extensions.Logging.Abstractions;
/// <summary>
/// A benchmark of sending network packets.
/// The memory allocation should be the same.
/// </summary>
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[MemoryDiagnoser]
[InvocationCount(100)]
public class PacketSending
{
private readonly byte[] _c1Packet = Convert.FromBase64String("wf8AudHEjjSP53H6Rkp3oXj7B9z+rVDR2f0Is4bvsIsUL3RM/aTDB2FX9YG3Hkboy1Z1JThot558MeDTvNuunzfl5RbWK6TTOP97prjPGbq3IOcweopTq3fVz8vD8EuFqVVJ0jgvEZ+xoe047RHmrRgmG5zzfSWtkTmeAVzZD0i09f1jhUeBiA5HfticGr5m7iGzndSvkSwvm0D/kRBD15GlhPgTgyfQpJONrP5NEHd7NxI6JnJzBWPQM+kHgvb+BKdH95bFUmv54vlBIeUt4ovIg1r9CLEfMX+UQk89yCKcj6dXBRjgteSmQUN5MuN9o1FePv6cAPv2KMUXMBAc");
/// <summary>
/// Gets or sets the packet count which will be tested.
/// </summary>
[Params(100, 500, 1000)]
public int PacketCount { get; set; }
/// <summary>
/// Sends packets at the connection with Spans.
/// </summary>
[Benchmark]
public async ValueTask SendSpanAsync()
{
CancellationToken cancellationToken = default;
var duplexPipe = new DuplexPipe();
using var connection = new Connection(duplexPipe, null, null, new NullLogger<Connection>());
for (int i = 0; i < this.PacketCount && !cancellationToken.IsCancellationRequested; i++)
{
using var l = await connection.OutputLock.LockAsync(cancellationToken).ConfigureAwait(false);
Write();
await connection.Output.FlushAsync(cancellationToken).ConfigureAwait(false);
}
void Write()
{
var span = connection.Output.GetSpan(this._c1Packet.Length);
this._c1Packet.CopyTo(span);
connection.Output.Advance(this._c1Packet.Length);
}
}
/// <summary>
/// Sends packets at the connection with Spans.
/// </summary>
[Benchmark]
public async ValueTask SendSpanInlineAsync()
{
CancellationToken cancellationToken = default;
var duplexPipe = new DuplexPipe();
using var connection = new Connection(duplexPipe, null, null, new NullLogger<Connection>());
for (int i = 0; i < this.PacketCount && !cancellationToken.IsCancellationRequested; i++)
{
using var l = await connection.OutputLock.LockAsync(cancellationToken).ConfigureAwait(false);
this._c1Packet.CopyTo(connection.Output.GetSpan(this._c1Packet.Length));
connection.Output.Advance(this._c1Packet.Length);
await connection.Output.FlushAsync(cancellationToken).ConfigureAwait(false);
}
}
}

View File

@@ -0,0 +1,29 @@
// <copyright file="Program.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
#pragma warning disable SA1200
global using BenchmarkDotNet.Attributes;
global using BenchmarkDotNet.Jobs;
global using BenchmarkDotNet.Running;
#pragma warning restore SA1200
namespace MUnique.OpenMU.Network.Benchmarks;
/// <summary>
/// The class of the entry point of the benchmark.
/// </summary>
public static class Program
{
/// <summary>
/// The entry point of the benchmark.
/// </summary>
/// <param name="args">The arguments.</param>
public static void Main(string[] args)
{
BenchmarkRunner.Run<EncryptionBenchmarks>();
BenchmarkRunner.Run<PacketSending>();
}
}

View File

@@ -0,0 +1,10 @@
// <copyright file="AssemblyInfo.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
using System.Reflection;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MUnique.OpenMU.Network.Benchmarks")]