Added first benchmarks

This commit is contained in:
Darth Affe 2024-07-11 00:24:39 +02:00
parent 02da924713
commit e020e460aa
3 changed files with 63 additions and 1 deletions

View File

@ -0,0 +1,58 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using HPPH.System.Drawing;
namespace HPPH.Benchmark;
[SimpleJob(RuntimeMoniker.Net80)]
[HtmlExporter]
[MemoryDiagnoser]
public class ConvertBenchmarks
{
#region Properties & Fields
private readonly List<ColorRGB[]> _colors = [];
#endregion
#region Constructors
public ConvertBenchmarks()
{
if (!Directory.Exists(@"..\..\..\..\sample_data")) return;
_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
#region Methods
[Benchmark]
public ColorBGR[] RGBToBGR()
{
ColorBGR[] result = [];
foreach (ColorRGB[] color in _colors)
{
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGR>();
}
return result;
}
[Benchmark]
public ColorBGRA[] RGBToBGRA()
{
ColorBGRA[] result = [];
foreach (ColorRGB[] color in _colors)
result = new ReadOnlySpan<ColorRGB>(color).Convert<ColorRGB, ColorBGRA>();
return result;
}
#endregion
}

View File

@ -13,6 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\HPPH.Reference\HPPH.Reference.csproj" />
<ProjectReference Include="..\HPPH.System.Drawing\HPPH.System.Drawing.csproj" />
<ProjectReference Include="..\HPPH\HPPH.csproj" />
</ItemGroup>

View File

@ -1 +1,4 @@
Console.WriteLine("Empty");
using BenchmarkDotNet.Running;
using HPPH.Benchmark;
BenchmarkRunner.Run<ConvertBenchmarks>();