Last active
December 10, 2022 15:51
-
-
Save TheVeryStarlk/abfa1b89d8dfdadac287ae1a800d4554 to your computer and use it in GitHub Desktop.
A benchmark of the NBT serializer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using Raspite.Library; | |
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(); | |
[MemoryDiagnoser] | |
public class Benchmark | |
{ | |
private byte[] source; | |
[GlobalSetup] | |
public async Task SetupAsync() | |
{ | |
var tag = new NbtTag.Compound() | |
{ | |
Name = "Parent", | |
Children = new NbtTag[] | |
{ | |
new NbtTag.Compound() | |
{ | |
Name = "Numbers", | |
Children = new NbtTag[] | |
{ | |
new NbtTag.Byte() | |
{ | |
Name = nameof(NbtTag.Byte), | |
Value = byte.MaxValue | |
}, | |
new NbtTag.Short() | |
{ | |
Name = nameof(NbtTag.Short), | |
Value = short.MaxValue | |
}, | |
new NbtTag.Int() | |
{ | |
Name = nameof(NbtTag.Int), | |
Value = int.MaxValue | |
}, | |
new NbtTag.Long() | |
{ | |
Name = nameof(NbtTag.Long), | |
Value = long.MaxValue | |
}, | |
new NbtTag.Compound() | |
{ | |
Name = "Special", | |
Children = new NbtTag[] | |
{ | |
new NbtTag.Float() | |
{ | |
Name = nameof(NbtTag.Float), | |
Value = float.MaxValue | |
}, | |
new NbtTag.Double() | |
{ | |
Name = nameof(NbtTag.Double), | |
Value = double.MaxValue | |
} | |
} | |
} | |
} | |
}, | |
new NbtTag.String() | |
{ | |
Name = nameof(NbtTag.String), | |
Value = nameof(Raspite) | |
} | |
} | |
}; | |
source = await NbtSerializer.DeserializeAsync(tag); | |
} | |
[Benchmark] | |
public async Task SerializeAsync() | |
{ | |
var _ = await NbtSerializer.SerializeAsync(source); | |
} | |
} | |
// | Method | Mean | Error | StdDev | Gen0 | Allocated | | |
// |--------------- |---------:|--------:|--------:|-------:|----------:| | |
// | SerializeAsync | 751.3 ns | 3.91 ns | 3.47 ns | 0.3109 | 1.27 KB | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment