|
|
|
@ -2,7 +2,6 @@ |
|
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
namespace ImageProcessorCore.Benchmarks.General |
|
|
|
{ |
|
|
|
using System; |
|
|
|
@ -15,38 +14,40 @@ namespace ImageProcessorCore.Benchmarks.General |
|
|
|
[Params(100, 1000, 10000)] |
|
|
|
public int Count { get; set; } |
|
|
|
|
|
|
|
byte[] source, destination; |
|
|
|
byte[] source; |
|
|
|
|
|
|
|
byte[] destination; |
|
|
|
|
|
|
|
[Setup] |
|
|
|
public void SetUp() |
|
|
|
{ |
|
|
|
source = new byte[Count]; |
|
|
|
destination = new byte[Count]; |
|
|
|
this.source = new byte[this.Count]; |
|
|
|
this.destination = new byte[this.Count]; |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark(Baseline = true, Description = "Copy using Array.Copy()")] |
|
|
|
public void CopyArray() |
|
|
|
{ |
|
|
|
Array.Copy(source, destination, Count); |
|
|
|
Array.Copy(this.source, this.destination, this.Count); |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark(Description = "Copy using Unsafe<T>")] |
|
|
|
public unsafe void CopyUnsafe() |
|
|
|
{ |
|
|
|
fixed (byte* pinnedDestination = destination) |
|
|
|
fixed (byte* pinnedSource = source) |
|
|
|
fixed (byte* pinnedDestination = this.destination) |
|
|
|
fixed (byte* pinnedSource = this.source) |
|
|
|
{ |
|
|
|
Unsafe.CopyBlock(pinnedSource, pinnedDestination, (uint)Count); |
|
|
|
Unsafe.CopyBlock(pinnedSource, pinnedDestination, (uint)this.Count); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Benchmark(Description = "Copy using Buffer.MemoryCopy<T>")] |
|
|
|
public unsafe void CopyUsingBufferMemoryCopy() |
|
|
|
{ |
|
|
|
fixed (byte* pinnedDestination = destination) |
|
|
|
fixed (byte* pinnedSource = source) |
|
|
|
fixed (byte* pinnedDestination = this.destination) |
|
|
|
fixed (byte* pinnedSource = this.source) |
|
|
|
{ |
|
|
|
Buffer.MemoryCopy(pinnedSource, pinnedDestination, Count, Count); |
|
|
|
Buffer.MemoryCopy(pinnedSource, pinnedDestination, this.Count, this.Count); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|