Implement buffer copy using different policies (#1599)

use Memory-Copy

Co-authored-by: Christian <6939810+chkr1011@users.noreply.github.com>
This commit is contained in:
老九
2022-12-03 13:17:02 +01:00
committed by GitHub
co-authored by Christian
parent 27f2474876
commit 862d76471b
7 changed files with 81 additions and 10 deletions
@@ -0,0 +1,40 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using System;
namespace MQTTnet.Benchmarks
{
[SimpleJob(RuntimeMoniker.Net60)]
[RPlotExporter, RankColumn]
[MemoryDiagnoser]
public class MemoryCopyBenchmark
{
const int max_length = 1024 * 8;
private byte[] source;
private byte[] target;
[Params(64 - 1, 128 - 1, 256 - 1, 512 - 1, 1024 - 1, 2048 - 1, 5096 - 1)]
public int Length { get; set; }
[GlobalSetup]
public void Setup()
{
source = new byte[max_length];
target = new byte[max_length];
}
[Benchmark(Baseline = true)]
public void Array_Copy()
{
Array.Copy(source, 0, target, 0, Length);
}
[Benchmark]
public void Memory_Copy()
{
MQTTnet.Internal.Memory.Copy(source, 0, target, 0, Length);
}
}
}