From e020e460aa98c083d9e9cfc823d9177affcad8e3 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 11 Jul 2024 00:24:39 +0200 Subject: [PATCH] Added first benchmarks --- HPPH.Benchmark/ConvertBenchmarks.cs | 58 ++++++++++++++++++++++++++++ HPPH.Benchmark/HPPH.Benchmark.csproj | 1 + HPPH.Benchmark/Program.cs | 5 ++- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 HPPH.Benchmark/ConvertBenchmarks.cs diff --git a/HPPH.Benchmark/ConvertBenchmarks.cs b/HPPH.Benchmark/ConvertBenchmarks.cs new file mode 100644 index 0000000..64dfdd1 --- /dev/null +++ b/HPPH.Benchmark/ConvertBenchmarks.cs @@ -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 _colors = []; + + #endregion + + #region Constructors + + public ConvertBenchmarks() + { + if (!Directory.Exists(@"..\..\..\..\sample_data")) return; + + _colors = []; + + IEnumerable files = Directory.EnumerateFiles(@"..\..\..\..\sample_data", "*.png", SearchOption.AllDirectories); + foreach (string file in files) + _colors.Add(ImageHelper.LoadImage(file).AsRefImage().ToArray()); + } + + #endregion + + #region Methods + + [Benchmark] + public ColorBGR[] RGBToBGR() + { + ColorBGR[] result = []; + foreach (ColorRGB[] color in _colors) + { + result = new ReadOnlySpan(color).Convert(); + } + + return result; + } + + [Benchmark] + public ColorBGRA[] RGBToBGRA() + { + ColorBGRA[] result = []; + foreach (ColorRGB[] color in _colors) + result = new ReadOnlySpan(color).Convert(); + + return result; + } + + #endregion +} \ No newline at end of file diff --git a/HPPH.Benchmark/HPPH.Benchmark.csproj b/HPPH.Benchmark/HPPH.Benchmark.csproj index d519e0a..1147eb0 100644 --- a/HPPH.Benchmark/HPPH.Benchmark.csproj +++ b/HPPH.Benchmark/HPPH.Benchmark.csproj @@ -13,6 +13,7 @@ + diff --git a/HPPH.Benchmark/Program.cs b/HPPH.Benchmark/Program.cs index a751bf5..6c7bb39 100644 --- a/HPPH.Benchmark/Program.cs +++ b/HPPH.Benchmark/Program.cs @@ -1 +1,4 @@ -Console.WriteLine("Empty"); \ No newline at end of file +using BenchmarkDotNet.Running; +using HPPH.Benchmark; + +BenchmarkRunner.Run();