mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
Added a bunch of benchmarks
This commit is contained in:
parent
cd4ad4de78
commit
cc8de89481
72
HPPH.Benchmark/AverageBenchmarks.cs
Normal file
72
HPPH.Benchmark/AverageBenchmarks.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class AverageBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public AverageBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGB[] PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
ColorRGB[] averages = new ColorRGB[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
averages[i] = new ReadOnlySpan<ColorRGB>(_colors3bpp[i]).Average();
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGBA[] PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
ColorRGBA[] averages = new ColorRGBA[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
averages[i] = new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]).Average();
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGB[] Reference_3BPP()
|
||||||
|
{
|
||||||
|
ColorRGB[] averages = new ColorRGB[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
averages[i] = ReferencePixelHelper.Average(new ReadOnlySpan<ColorRGB>(_colors3bpp[i]));
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorRGBA[] Reference_4BPP()
|
||||||
|
{
|
||||||
|
ColorRGBA[] averages = new ColorRGBA[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
averages[i] = ReferencePixelHelper.Average(new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]));
|
||||||
|
|
||||||
|
return averages;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
22
HPPH.Benchmark/BenchmarkHelper.cs
Normal file
22
HPPH.Benchmark/BenchmarkHelper.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using HPPH.System.Drawing;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
internal static class BenchmarkHelper
|
||||||
|
{
|
||||||
|
private const string SAMPLE_DATA_DIR = @"..\..\..\..\..\..\..\..\sample_data";
|
||||||
|
|
||||||
|
public static List<T[]> GetSampleData<T>()
|
||||||
|
where T : struct, IColor
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(SAMPLE_DATA_DIR)) throw new Exception("sample data not found!");
|
||||||
|
|
||||||
|
List<T[]> colors = [];
|
||||||
|
|
||||||
|
IEnumerable<string> files = Directory.EnumerateFiles(SAMPLE_DATA_DIR, "*.png", SearchOption.AllDirectories);
|
||||||
|
foreach (string file in files)
|
||||||
|
colors.Add(ImageHelper.LoadImage(file).ConvertTo<T>().ToArray());
|
||||||
|
|
||||||
|
return colors;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
using BenchmarkDotNet.Attributes;
|
using BenchmarkDotNet.Attributes;
|
||||||
using BenchmarkDotNet.Jobs;
|
using BenchmarkDotNet.Jobs;
|
||||||
using HPPH.System.Drawing;
|
|
||||||
|
|
||||||
namespace HPPH.Benchmark;
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
@ -11,7 +10,8 @@ public class ConvertBenchmarks
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
private readonly List<ColorRGB[]> _colors = [];
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -19,13 +19,8 @@ public class ConvertBenchmarks
|
|||||||
|
|
||||||
public ConvertBenchmarks()
|
public ConvertBenchmarks()
|
||||||
{
|
{
|
||||||
if (!Directory.Exists(@"..\..\..\..\sample_data")) return;
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
_colors = [];
|
|
||||||
|
|
||||||
IEnumerable<string> files = Directory.EnumerateFiles(@"..\..\..\..\sample_data", "*.png", SearchOption.AllDirectories);
|
|
||||||
foreach (string file in files)
|
|
||||||
_colors.Add(ImageHelper.LoadImage(file).AsRefImage<ColorRGB>().ToArray());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -36,10 +31,8 @@ public class ConvertBenchmarks
|
|||||||
public ColorBGR[] RGBToBGR()
|
public ColorBGR[] RGBToBGR()
|
||||||
{
|
{
|
||||||
ColorBGR[] result = [];
|
ColorBGR[] result = [];
|
||||||
foreach (ColorRGB[] color in _colors)
|
foreach (ColorRGB[] color in _colors3bpp)
|
||||||
{
|
|
||||||
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGR>();
|
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGR>();
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -48,11 +41,45 @@ public class ConvertBenchmarks
|
|||||||
public ColorBGRA[] RGBToBGRA()
|
public ColorBGRA[] RGBToBGRA()
|
||||||
{
|
{
|
||||||
ColorBGRA[] result = [];
|
ColorBGRA[] result = [];
|
||||||
foreach (ColorRGB[] color in _colors)
|
foreach (ColorRGB[] color in _colors3bpp)
|
||||||
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGRA>();
|
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGRA>();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorABGR[] RGBAToABGR()
|
||||||
|
{
|
||||||
|
ColorABGR[] result = [];
|
||||||
|
foreach (ColorRGBA[] color in _colors4bpp)
|
||||||
|
result = new ReadOnlySpan<ColorRGBA>(color).Convert<ColorRGBA, ColorABGR>();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ColorBGR[] ARGBToBGR()
|
||||||
|
{
|
||||||
|
ColorBGR[] result = [];
|
||||||
|
foreach (ColorRGBA[] color in _colors4bpp)
|
||||||
|
result = new ReadOnlySpan<ColorRGBA>(color).Convert<ColorRGBA, ColorBGR>();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void RGBToBGR_InPlace()
|
||||||
|
{
|
||||||
|
foreach (ColorRGB[] color in _colors3bpp)
|
||||||
|
new Span<ColorRGB>(color).ConvertInPlace<ColorRGB, ColorBGR>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void RGBAToABGR_InPlace()
|
||||||
|
{
|
||||||
|
foreach (ColorRGBA[] color in _colors4bpp)
|
||||||
|
new Span<ColorRGBA>(color).ConvertInPlace<ColorRGBA, ColorABGR>();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
72
HPPH.Benchmark/MinMaxBenchmarks.cs
Normal file
72
HPPH.Benchmark/MinMaxBenchmarks.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class MinMaxBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public MinMaxBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
minMax[i] = new ReadOnlySpan<ColorRGB>(_colors3bpp[i]).MinMax();
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
minMax[i] = new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]).MinMax();
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] Reference_3BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
minMax[i] = ReferencePixelHelper.MinMax(new ReadOnlySpan<ColorRGB>(_colors3bpp[i]));
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public IMinMax[] Reference_4BPP()
|
||||||
|
{
|
||||||
|
IMinMax[] minMax = new IMinMax[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
minMax[i] = ReferencePixelHelper.MinMax(new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]));
|
||||||
|
|
||||||
|
return minMax;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@ -1,4 +1,4 @@
|
|||||||
using BenchmarkDotNet.Running;
|
using BenchmarkDotNet.Running;
|
||||||
using HPPH.Benchmark;
|
using HPPH.Benchmark;
|
||||||
|
|
||||||
BenchmarkRunner.Run<ConvertBenchmarks>();
|
BenchmarkRunner.Run(typeof(Program).Assembly);
|
||||||
60
HPPH.Benchmark/SortBenchmarks.cs
Normal file
60
HPPH.Benchmark/SortBenchmarks.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class SortBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public SortBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGB[] colors in _colors3bpp)
|
||||||
|
new Span<ColorRGB>(colors).SortByRed();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGBA[] colors in _colors4bpp)
|
||||||
|
new Span<ColorRGBA>(colors).SortByRed();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void Reference_3BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGB[] colors in _colors3bpp)
|
||||||
|
ReferencePixelHelper.SortByRed(new Span<ColorRGB>(colors));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public void Reference_4BPP()
|
||||||
|
{
|
||||||
|
foreach (ColorRGBA[] colors in _colors4bpp)
|
||||||
|
ReferencePixelHelper.SortByRed(new Span<ColorRGBA>(colors));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
72
HPPH.Benchmark/SumBenchmarks.cs
Normal file
72
HPPH.Benchmark/SumBenchmarks.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using BenchmarkDotNet.Jobs;
|
||||||
|
using HPPH.Reference;
|
||||||
|
|
||||||
|
namespace HPPH.Benchmark;
|
||||||
|
|
||||||
|
[SimpleJob(RuntimeMoniker.Net80)]
|
||||||
|
[HtmlExporter]
|
||||||
|
[MemoryDiagnoser]
|
||||||
|
public class SumBenchmarks
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
private readonly List<ColorRGB[]> _colors3bpp;
|
||||||
|
private readonly List<ColorRGBA[]> _colors4bpp;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public SumBenchmarks()
|
||||||
|
{
|
||||||
|
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
|
||||||
|
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] PixelHelper_3BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
sums[i] = new ReadOnlySpan<ColorRGB>(_colors3bpp[i]).Sum();
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] PixelHelper_4BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
sums[i] = new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]).Sum();
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] Reference_3BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors3bpp.Count];
|
||||||
|
for (int i = 0; i < _colors3bpp.Count; i++)
|
||||||
|
sums[i] = ReferencePixelHelper.Sum(new ReadOnlySpan<ColorRGB>(_colors3bpp[i]));
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public ISum[] Reference_4BPP()
|
||||||
|
{
|
||||||
|
ISum[] sums = new ISum[_colors4bpp.Count];
|
||||||
|
for (int i = 0; i < _colors4bpp.Count; i++)
|
||||||
|
sums[i] = ReferencePixelHelper.Sum(new ReadOnlySpan<ColorRGBA>(_colors4bpp[i]));
|
||||||
|
|
||||||
|
return sums;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user