Browse Source

more benchmarks

af/merge-core
Anton Firszov 9 years ago
parent
commit
955a61752a
  1. 54
      tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs
  2. 54
      tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs
  3. 69
      tests/ImageSharp.Benchmarks/General/Vectorization/Divide.cs
  4. 67
      tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs
  5. 54
      tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs
  6. 50
      tests/ImageSharp.Benchmarks/General/Vectorization/Multiply.cs
  7. 70
      tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs
  8. 38
      tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs
  9. 2
      tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs

54
tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs

@ -1,54 +0,0 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class DivFloat
{
private float[] input;
private float[] result;
[Params(32)]
public int InputSize { get; set; }
private float testValue;
[GlobalSetup]
public void Setup()
{
this.input = new float[this.InputSize];
this.result = new float[this.InputSize];
this.testValue = 42;
for (int i = 0; i < this.InputSize; i++)
{
this.input[i] = (uint)i;
}
}
[Benchmark(Baseline = true)]
public void Standard()
{
float v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] / v;
}
}
[Benchmark]
public void Simd()
{
Vector<float> v = new Vector<float>(this.testValue);
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<float> a = new Vector<float>(this.input, i);
a = a / v;
a.CopyTo(this.result, i);
}
}
}
}

54
tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs

@ -1,54 +0,0 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class DivUInt32
{
private uint[] input;
private uint[] result;
[Params(32)]
public int InputSize { get; set; }
private uint testValue;
[GlobalSetup]
public void Setup()
{
this.input = new uint[this.InputSize];
this.result = new uint[this.InputSize];
this.testValue = 42;
for (int i = 0; i < this.InputSize; i++)
{
this.input[i] = (uint)i;
}
}
[Benchmark(Baseline = true)]
public void Standard()
{
uint v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] / v;
}
}
[Benchmark]
public void Simd()
{
Vector<uint> v = new Vector<uint>(this.testValue);
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<uint> a = new Vector<uint>(this.input, i);
a = a / v;
a.CopyTo(this.result, i);
}
}
}
}

69
tests/ImageSharp.Benchmarks/General/Vectorization/Divide.cs

@ -0,0 +1,69 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System;
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class DivFloat : SIMDBenchmarkBase<float>.Divide
{
protected override float GetTestValue() => 42;
[Benchmark(Baseline = true)]
public void Standard()
{
float v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] / v;
}
}
}
public class Divide : SIMDBenchmarkBase<uint>.Divide
{
protected override uint GetTestValue() => 42;
[Benchmark(Baseline = true)]
public void Standard()
{
uint v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] / v;
}
}
}
public class DivInt32 : SIMDBenchmarkBase<int>.Divide
{
protected override int GetTestValue() => 42;
[Benchmark(Baseline = true)]
public void Standard()
{
int v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] / v;
}
}
}
public class DivInt16 : SIMDBenchmarkBase<short>.Divide
{
protected override short GetTestValue() => 42;
protected override Vector<short> GetTestVector() => new Vector<short>(new short[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17});
[Benchmark(Baseline = true)]
public void Standard()
{
short v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = (short)(this.input[i] / v);
}
}
}
}

67
tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs

@ -1,67 +0,0 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class MulFloat
{
private float[] input;
private float[] result;
[Params(32)]
public int InputSize { get; set; }
private float testValue;
[GlobalSetup]
public void Setup()
{
this.input = new float[this.InputSize];
this.result = new float[this.InputSize];
this.testValue = 42;
for (int i = 0; i < this.InputSize; i++)
{
this.input[i] = i;
}
}
[Benchmark(Baseline = true)]
public void Standard()
{
float v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] * v;
}
}
[Benchmark]
public void SimdMultiplyByVector()
{
Vector<float> v = new Vector<float>(this.testValue);
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<float> a = new Vector<float>(this.input, i);
a = a * v;
a.CopyTo(this.result, i);
}
}
[Benchmark]
public void SimdMultiplyByScalar()
{
float v = this.testValue;
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<float> a = new Vector<float>(this.input, i);
a = a * v;
a.CopyTo(this.result, i);
}
}
}
}

54
tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs

@ -1,54 +0,0 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class MulUInt32
{
private uint[] input;
private uint[] result;
[Params(32)]
public int InputSize { get; set; }
private uint testValue;
[GlobalSetup]
public void Setup()
{
this.input = new uint[this.InputSize];
this.result = new uint[this.InputSize];
this.testValue = 42;
for (int i = 0; i < this.InputSize; i++)
{
this.input[i] = (uint)i;
}
}
[Benchmark(Baseline = true)]
public void Standard()
{
uint v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] * v;
}
}
[Benchmark]
public void Simd()
{
Vector<uint> v = new Vector<uint>(this.testValue);
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<uint> a = new Vector<uint>(this.input, i);
a = a * v;
a.CopyTo(this.result, i);
}
}
}
}

50
tests/ImageSharp.Benchmarks/General/Vectorization/Multiply.cs

@ -0,0 +1,50 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class MulUInt32 : SIMDBenchmarkBase<uint>.Multiply
{
protected override uint GetTestValue() => 42u;
[Benchmark(Baseline = true)]
public void Standard()
{
uint v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] * v;
}
}
}
public class MulInt32 : SIMDBenchmarkBase<int>.Multiply
{
[Benchmark(Baseline = true)]
public void Standard()
{
int v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] * v;
}
}
}
public class MulInt16 : SIMDBenchmarkBase<short>.Multiply
{
protected override short GetTestValue() => 42;
protected override Vector<short> GetTestVector() => new Vector<short>(new short[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 });
[Benchmark(Baseline = true)]
public void Standard()
{
short v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = (short)(this.input[i] * v);
}
}
}
}

70
tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

@ -0,0 +1,70 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
public abstract class SIMDBenchmarkBase<T>
where T : struct
{
protected T[] input;
protected T[] result;
protected T testValue;
protected Vector<T> testVector;
protected virtual T GetTestValue() => default(T);
protected virtual Vector<T> GetTestVector() => new Vector<T>(this.GetTestValue());
[Params(32)]
public int InputSize { get; set; }
[GlobalSetup]
public virtual void Setup()
{
this.input = new T[this.InputSize];
this.result = new T[this.InputSize];
this.testValue = this.GetTestValue();
this.testVector = this.GetTestVector();
}
public abstract class Multiply : SIMDBenchmarkBase<T>
{
[Benchmark]
public void Simd()
{
Vector<T> v = this.testVector;
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<T> a = Unsafe.As<T, Vector<T>>(ref this.input[i]);
a = a * v;
Unsafe.As<T, Vector<T>>(ref this.result[i]) = a;
}
}
}
public abstract class Divide : SIMDBenchmarkBase<T>
{
[Benchmark]
public void Simd()
{
Vector<T> v = this.testVector;
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<T> a = Unsafe.As<T, Vector<T>>(ref this.input[i]);
a = a / v;
Unsafe.As<T, Vector<T>>(ref this.result[i]) = a;
}
}
}
}
}

38
tests/ImageSharp.Benchmarks/Image/DecodeJpegMultiple.cs

@ -6,8 +6,13 @@
namespace ImageSharp.Benchmarks.Image
{
using System.Collections.Generic;
using System.IO;
using BenchmarkDotNet.Attributes;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
using CoreImage = ImageSharp.Image;
[Config(typeof(Config.Short))]
@ -20,14 +25,23 @@ namespace ImageSharp.Benchmarks.Image
protected override IEnumerable<string> SearchPatterns => new[] { "*.jpg" };
[Benchmark(Description = "DecodeJpegMultiple - ImageSharp")]
public void DecodeJpegImageSharp()
[Benchmark(Description = "DecodeJpegMultiple - ImageSharp NEW")]
public void DecodeJpegImageSharpNwq()
{
this.ForEachStream(
ms => CoreImage.Load<Rgba32>(ms)
);
}
[Benchmark(Description = "DecodeJpegMultiple - ImageSharp Original")]
public void DecodeJpegImageSharpOriginal()
{
this.ForEachStream(
ms => CoreImage.Load<Rgba32>(ms, new OriginalJpegDecoder())
);
}
[Benchmark(Baseline = true, Description = "DecodeJpegMultiple - System.Drawing")]
public void DecodeJpegSystemDrawing()
{
@ -36,5 +50,25 @@ namespace ImageSharp.Benchmarks.Image
);
}
public sealed class OriginalJpegDecoder : IImageDecoder, IJpegDecoderOptions
{
/// <summary>
/// Gets or sets a value indicating whether the metadata should be ignored when the image is being decoded.
/// </summary>
public bool IgnoreMetadata { get; set; }
/// <inheritdoc/>
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream)
where TPixel : struct, IPixel<TPixel>
{
Guard.NotNull(stream, "stream");
using (var decoder = new JpegDecoderCore(configuration, this))
{
return decoder.Decode<TPixel>(stream);
}
}
}
}
}

2
tests/ImageSharp.Benchmarks/Image/MultiImageBenchmarkBase.cs

@ -39,7 +39,7 @@ namespace ImageSharp.Benchmarks.Image
[Params(InputImageCategory.AllImages, InputImageCategory.SmallImagesOnly, InputImageCategory.LargeImagesOnly)]
public virtual InputImageCategory InputCategory { get; set; }
protected virtual string BaseFolder => "../ImageSharp.Tests/TestImages/Formats/";
protected virtual string BaseFolder => "../../../../../../../../ImageSharp.Tests/TestImages/Formats/";
protected virtual IEnumerable<string> SearchPatterns => new[] { "*.*" };

Loading…
Cancel
Save