Added examples, Added performance tests, Updated readme

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-11-03 16:51:37 +01:00
parent 3d259d363a
commit 9facb66ee8
44 changed files with 3295 additions and 32 deletions
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MessagePack" Version="3.1.12" />
<Compile Include="..\..\_PerfTesting.cs" Link="_PerfTesting.cs" />
</ItemGroup>
</Project>
@@ -0,0 +1,62 @@
// Writes, reads and skips the workload shared with the PureBasic tests, see `../_Workload.pbi`.
// Uses the low-level MessagePackWriter/MessagePackReader from MessagePack-CSharp, pinned in the .csproj.
using System.Buffers;
using MessagePack;
const int Records = 125_000;
const int Fields = Records * 8;
byte[] encoded = Write();
Perf.Run("write", Fields, () => Write().Length);
Perf.Run("read", Fields, () => Read(encoded));
Perf.Run("skip", Fields, () => Skip(encoded));
return 0;
static byte[] Write()
{
var buffer = new ArrayBufferWriter<byte>();
var writer = new MessagePackWriter(buffer);
for (int i = 0; i < Records; i++)
{
writer.Write(42);
writer.Write(-5);
writer.Write(200);
writer.Write(-1000);
writer.Write(70000);
writer.Write(-1099511627776L);
writer.Write(3.14);
writer.Write("Hello");
}
writer.Flush();
return buffer.WrittenSpan.ToArray();
}
static long Read(byte[] data)
{
var reader = new MessagePackReader(data);
long total = 0;
for (int i = 0; i < Records; i++)
{
total += reader.ReadInt64();
total += reader.ReadInt64();
total += reader.ReadInt64();
total += reader.ReadInt64();
total += reader.ReadInt64();
total += reader.ReadInt64();
total += (long)reader.ReadDouble();
total += reader.ReadString()!.Length;
}
return total;
}
static long Skip(byte[] data)
{
var reader = new MessagePackReader(data);
for (int i = 0; i < Fields; i++)
{
reader.Skip();
}
return Fields;
}