Browse Source

Cleanup benchmarks

Former-commit-id: 2e9c25a66e2d6125f1dbaf143544c147b024c32c
Former-commit-id: 62f3d61bc6faa7535a371c782879e413c3e30bfa
Former-commit-id: cab675a891e4b30bfe8029046f3431c973dd1eb7
af/merge-core
James Jackson-South 10 years ago
parent
commit
42b3639d5c
  1. 23
      tests/ImageProcessorCore.Benchmarks/General/ArrayCopy.cs
  2. 3
      tests/ImageProcessorCore.Benchmarks/Samplers/Crop.cs
  3. 29
      tests/ImageProcessorCore.Benchmarks/Samplers/DetectEdges.cs

23
tests/ImageProcessorCore.Benchmarks/General/ArrayCopy.cs

@ -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);
}
}
}

3
tests/ImageProcessorCore.Benchmarks/Samplers/Crop.cs

@ -9,8 +9,9 @@ namespace ImageProcessorCore.Benchmarks
using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
using CoreSize = ImageProcessorCore.Size;
using CoreImage = ImageProcessorCore.Image;
using CoreSize = ImageProcessorCore.Size;
public class Crop
{

29
tests/ImageProcessorCore.Benchmarks/Samplers/DetectEdges.cs

@ -3,7 +3,6 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore.Benchmarks
{
using System.IO;
@ -19,11 +18,11 @@ namespace ImageProcessorCore.Benchmarks
[Setup]
public void ReadImage()
{
if (image == null)
if (this.image == null)
{
using(FileStream stream = File.OpenRead("../ImageProcessorCore.Tests/TestImages/Formats/Bmp/Car.bmp"))
using (FileStream stream = File.OpenRead("../ImageProcessorCore.Tests/TestImages/Formats/Bmp/Car.bmp"))
{
image = new CoreImage(stream);
this.image = new CoreImage(stream);
}
}
}
@ -31,17 +30,17 @@ namespace ImageProcessorCore.Benchmarks
[Benchmark(Description = "ImageProcessorCore DetectEdges")]
public void ImageProcessorCoreDetectEdges()
{
image.DetectEdges(EdgeDetection.Kayyali);
image.DetectEdges(EdgeDetection.Kayyali);
image.DetectEdges(EdgeDetection.Kirsch);
image.DetectEdges(EdgeDetection.Lapacian3X3);
image.DetectEdges(EdgeDetection.Lapacian5X5);
image.DetectEdges(EdgeDetection.LaplacianOfGaussian);
image.DetectEdges(EdgeDetection.Prewitt);
image.DetectEdges(EdgeDetection.RobertsCross);
image.DetectEdges(EdgeDetection.Robinson);
image.DetectEdges(EdgeDetection.Scharr);
image.DetectEdges(EdgeDetection.Sobel);
this.image.DetectEdges(EdgeDetection.Kayyali);
this.image.DetectEdges(EdgeDetection.Kayyali);
this.image.DetectEdges(EdgeDetection.Kirsch);
this.image.DetectEdges(EdgeDetection.Lapacian3X3);
this.image.DetectEdges(EdgeDetection.Lapacian5X5);
this.image.DetectEdges(EdgeDetection.LaplacianOfGaussian);
this.image.DetectEdges(EdgeDetection.Prewitt);
this.image.DetectEdges(EdgeDetection.RobertsCross);
this.image.DetectEdges(EdgeDetection.Robinson);
this.image.DetectEdges(EdgeDetection.Scharr);
this.image.DetectEdges(EdgeDetection.Sobel);
}
}
}

Loading…
Cancel
Save