mirror of https://github.com/SixLabors/ImageSharp
23 changed files with 97 additions and 113 deletions
@ -0,0 +1,31 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using BenchmarkDotNet.Attributes; |
|||
using SixLabors.ImageSharp.Processing; |
|||
|
|||
namespace SixLabors.ImageSharp.Benchmarks.Bulk; |
|||
|
|||
public class ColorMatrixTransforms |
|||
{ |
|||
private static readonly Vector4[] Vectors = Vector4Factory.CreateVectors(); |
|||
|
|||
[Benchmark(Baseline = true)] |
|||
public void Transform() |
|||
{ |
|||
ColorMatrix matrix = KnownFilterMatrices.CreateHueFilter(45F); |
|||
for (int i = 0; i < Vectors.Length; i++) |
|||
{ |
|||
ref Vector4 input = ref Vectors[i]; |
|||
ColorNumerics.Transform(ref input, ref matrix); |
|||
} |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void Transform_Span() |
|||
{ |
|||
ColorMatrix matrix = KnownFilterMatrices.CreateHueFilter(45F); |
|||
ColorNumerics.Transform(Vectors.AsSpan(), ref matrix); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
|
|||
namespace SixLabors.ImageSharp.Benchmarks.Bulk; |
|||
|
|||
internal static class Vector4Factory |
|||
{ |
|||
public static Vector4[] CreateVectors(int length = 2048, int min = 0, int max = 1) |
|||
{ |
|||
Random rnd = new(42); |
|||
return GenerateRandomVectorArray(rnd, length, min, max); |
|||
} |
|||
|
|||
private static Vector4[] GenerateRandomVectorArray(Random rnd, int length, float minVal, float maxVal) |
|||
{ |
|||
Vector4[] values = new Vector4[length]; |
|||
|
|||
for (int i = 0; i < length; i++) |
|||
{ |
|||
ref Vector4 v = ref values[i]; |
|||
v.X = GetRandomFloat(rnd, minVal, maxVal); |
|||
v.Y = GetRandomFloat(rnd, minVal, maxVal); |
|||
v.Z = GetRandomFloat(rnd, minVal, maxVal); |
|||
v.W = GetRandomFloat(rnd, minVal, maxVal); |
|||
} |
|||
|
|||
return values; |
|||
} |
|||
|
|||
private static float GetRandomFloat(Random rnd, float minVal, float maxVal) |
|||
=> (float)rnd.NextDouble() * (maxVal - minVal) + minVal; |
|||
} |
|||
@ -1,34 +0,0 @@ |
|||
// Copyright (c) Six Labors.
|
|||
// Licensed under the Six Labors Split License.
|
|||
|
|||
using System.Numerics; |
|||
using BenchmarkDotNet.Attributes; |
|||
using SixLabors.ImageSharp.Processing; |
|||
|
|||
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization; |
|||
|
|||
[Config(typeof(Config.MultiFramework))] |
|||
public class ColorNumerics |
|||
{ |
|||
private static Vector4[] input = |
|||
{ |
|||
new(.5F), new(.5F), new(.5F), new(.5F), new(.5F), new(.5F), new(.5F), |
|||
}; |
|||
|
|||
[Benchmark] |
|||
public Vector4 Transform() |
|||
{ |
|||
Vector4 input = new(.5F); |
|||
ColorMatrix matrix = KnownFilterMatrices.CreateHueFilter(45F); |
|||
ImageSharp.ColorNumerics.Transform(ref input, ref matrix); |
|||
|
|||
return input; |
|||
} |
|||
|
|||
[Benchmark] |
|||
public void Transform_Span() |
|||
{ |
|||
ColorMatrix matrix = KnownFilterMatrices.CreateHueFilter(45F); |
|||
ImageSharp.ColorNumerics.Transform(input.AsSpan(), ref matrix); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue