mirror of
https://github.com/DarthAffe/HPPH.git
synced 2025-12-12 13:28:37 +00:00
Added first benchmarks
This commit is contained in:
parent
02da924713
commit
e020e460aa
58
HPPH.Benchmark/ConvertBenchmarks.cs
Normal file
58
HPPH.Benchmark/ConvertBenchmarks.cs
Normal 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
|
||||
}
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -1 +1,4 @@
|
||||
Console.WriteLine("Empty");
|
||||
using BenchmarkDotNet.Running;
|
||||
using HPPH.Benchmark;
|
||||
|
||||
BenchmarkRunner.Run<ConvertBenchmarks>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user