memcpy-bench

Do you mind sending the benchmark code I'd love to see if there is a difference between .Net 5 and .Net 6
1 Reply
TechPizza
TechPizza3y ago
public class CopyBlockVsSpan
{
public double[] source;
public double[] destination;

[Params(/*16, 64, 256, 1024, 2048, 4096*/ 1024 * 64, 1024 * 1024, 1024 * 1024 * 16)]
public int Size { get; set; }

[GlobalSetup]
public void Setup()
{
source = new double[Size];
destination = new double[Size];
}

[Benchmark]
public void CopyBlock()
{
Unsafe.CopyBlock(ref Unsafe.As<double, byte>(ref destination[0]), ref Unsafe.As<double, byte>(ref source[0]), (uint)Size * sizeof(double));
}

[Benchmark]
public void Span()
{
source.AsSpan(0, Size).CopyTo(destination);
}
}
public class CopyBlockVsSpan
{
public double[] source;
public double[] destination;

[Params(/*16, 64, 256, 1024, 2048, 4096*/ 1024 * 64, 1024 * 1024, 1024 * 1024 * 16)]
public int Size { get; set; }

[GlobalSetup]
public void Setup()
{
source = new double[Size];
destination = new double[Size];
}

[Benchmark]
public void CopyBlock()
{
Unsafe.CopyBlock(ref Unsafe.As<double, byte>(ref destination[0]), ref Unsafe.As<double, byte>(ref source[0]), (uint)Size * sizeof(double));
}

[Benchmark]
public void Span()
{
source.AsSpan(0, Size).CopyTo(destination);
}
}
trivial stuff i doubt net6 will improve this