Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions SimpleBinarySerialization.Benchmakrs/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using BenchmarkDotNet.Running;

namespace SimpleBinarySerialization.Benchmakrs
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace 'Benchmakrs' is misspelled. It should be 'Benchmarks'.

Suggested change
namespace SimpleBinarySerialization.Benchmakrs
namespace SimpleBinarySerialization.Benchmarks

Copilot uses AI. Check for mistakes.
{
internal class Program
{
static void Main(string[] args)
{
var _ = BenchmarkRunner.Run(typeof(Program).Assembly);
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assignment to _ is useless, since its value is never read.

Suggested change
var _ = BenchmarkRunner.Run(typeof(Program).Assembly);
BenchmarkRunner.Run(typeof(Program).Assembly);

Copilot uses AI. Check for mistakes.
}
}
}
67 changes: 67 additions & 0 deletions SimpleBinarySerialization.Benchmakrs/SerilizationBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using BenchmarkDotNet.Attributes;
using MemoryPack;
using System.Text.Json.Serialization;

namespace SimpleBinarySerialization.Benchmakrs;
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace 'Benchmakrs' is misspelled. It should be 'Benchmarks'.

Suggested change
namespace SimpleBinarySerialization.Benchmakrs;
namespace SimpleBinarySerialization.Benchmarks;

Copilot uses AI. Check for mistakes.

[MemoryDiagnoser]
public class SerilizationBenchmark
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class name 'SerilizationBenchmark' is misspelled. It should be 'SerializationBenchmark'.

Suggested change
public class SerilizationBenchmark
public class SerializationBenchmark

Copilot uses AI. Check for mistakes.
{
private User obj = null!;
public int Length { get; set; }
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'Length' property is declared but never used in the benchmark class. Consider removing it if it's not needed.

Suggested change
public int Length { get; set; }

Copilot uses AI. Check for mistakes.

private SimpleBinarySerializer serializer = new();
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field 'serializer' can be 'readonly'.

Suggested change
private SimpleBinarySerializer serializer = new();
private readonly SimpleBinarySerializer serializer = new();

Copilot uses AI. Check for mistakes.

[GlobalSetup]
public void Setup()
{
obj = new User { Age = 30, Score = 99.9f, Name = "TestUser" };
}

[Benchmark]
public object SimpleBinary()
{
return serializer.Deserialize<User>(serializer.Serialize(obj));
}

[Benchmark]
public object TextJson()
{
return System.Text.Json.JsonSerializer.Deserialize<User>(System.Text.Json.JsonSerializer.Serialize(obj));
}

[Benchmark]
public object TextJsonSG()
{
return System.Text.Json.JsonSerializer.Deserialize<User>(System.Text.Json.JsonSerializer.Serialize(obj, TextJsonGenerator.Default.User), TextJsonGenerator.Default.User);
}

[Benchmark]
public object NewtonsoftJson()
{
return Newtonsoft.Json.JsonConvert.DeserializeObject<User>(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
}

[Benchmark]
public object MemoryPack()
{
var bytes = MemoryPackSerializer.Serialize<User>(obj);
return MemoryPackSerializer.Deserialize<User>(bytes);
}
}

[MemoryPackable]
public partial class User
{
public int Age { get; set; }

public float Score { get; set; }

public string Name { get; set; }
}

[JsonSerializable(typeof(User))]
public partial class TextJsonGenerator : JsonSerializerContext
{

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.15.2" />
<PackageReference Include="MemoryPack" Version="1.21.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\SimpleBinarySerialization\SimpleBinarySerialization.csproj" />
</ItemGroup>
</Project>
10 changes: 8 additions & 2 deletions SimpleBinarySerialization.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.13.35825.156 d17.13
# Visual Studio Version 18
VisualStudioVersion = 18.0.11123.170
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleBinarySerialization", "SimpleBinarySerialization\SimpleBinarySerialization.csproj", "{ECAA2430-866C-467B-8B77-D9DAA629D8CC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleBinarySerialization.Benchmakrs", "SimpleBinarySerialization.Benchmakrs\SimpleBinarySerialization.Benchmakrs.csproj", "{E127D779-53D4-44F7-AB74-B2BF10CB3DEF}"
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The project name 'Benchmakrs' is misspelled. It should be 'Benchmarks'.

Suggested change
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleBinarySerialization.Benchmakrs", "SimpleBinarySerialization.Benchmakrs\SimpleBinarySerialization.Benchmakrs.csproj", "{E127D779-53D4-44F7-AB74-B2BF10CB3DEF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleBinarySerialization.Benchmarks", "SimpleBinarySerialization.Benchmarks\SimpleBinarySerialization.Benchmarks.csproj", "{E127D779-53D4-44F7-AB74-B2BF10CB3DEF}"

Copilot uses AI. Check for mistakes.
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{ECAA2430-866C-467B-8B77-D9DAA629D8CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECAA2430-866C-467B-8B77-D9DAA629D8CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECAA2430-866C-467B-8B77-D9DAA629D8CC}.Release|Any CPU.Build.0 = Release|Any CPU
{E127D779-53D4-44F7-AB74-B2BF10CB3DEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E127D779-53D4-44F7-AB74-B2BF10CB3DEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E127D779-53D4-44F7-AB74-B2BF10CB3DEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E127D779-53D4-44F7-AB74-B2BF10CB3DEF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down