mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
using System;
|
|
using System.Runtime.CompilerServices;
|
|
|
|
namespace ImageProcessorCore.Benchmarks.General
|
|
{
|
|
using BenchmarkDotNet.Attributes;
|
|
|
|
public class ArrayCopy
|
|
{
|
|
[Params(100, 1000, 10000)]
|
|
public int Count { get; set; }
|
|
|
|
byte[] source, destination;
|
|
|
|
long sizeInBytes;
|
|
|
|
[Setup]
|
|
public void SetUp()
|
|
{
|
|
source = new byte[Count];
|
|
destination = new byte[Count];
|
|
}
|
|
|
|
[Benchmark(Baseline = true, Description = "Copy using Array.Copy()")]
|
|
public void CopyArray()
|
|
{
|
|
Array.Copy(source, destination, Count);
|
|
}
|
|
|
|
[Benchmark(Description = "Copy using Unsafe<T>")]
|
|
public unsafe void CopyUnsafe()
|
|
{
|
|
fixed (byte* pinnedDestination = destination)
|
|
fixed (byte* pinnedSource = source)
|
|
{
|
|
Unsafe.CopyBlock(pinnedSource, pinnedDestination, (uint)Count);
|
|
}
|
|
}
|
|
|
|
[Benchmark(Description = "Copy using Buffer.MemoryCopy<T>")]
|
|
public unsafe void CopyUsingBufferMemoryCopy()
|
|
{
|
|
fixed (byte* pinnedDestination = destination)
|
|
fixed (byte* pinnedSource = source)
|
|
{
|
|
Buffer.MemoryCopy(pinnedSource, pinnedDestination, Count, Count);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|