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 _colors3bpp; private readonly List _colors4bpp; private readonly List> _images3bpp; private readonly List> _images4bpp; #endregion #region Constructors public MinMaxBenchmarks() { _colors3bpp = BenchmarkHelper.GetSampleData(); _colors4bpp = BenchmarkHelper.GetSampleData(); _images3bpp = BenchmarkHelper.GetSampleDataImages(); _images4bpp = BenchmarkHelper.GetSampleDataImages(); } #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(_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(_colors4bpp[i]).MinMax(); return minMax; } [Benchmark] public IMinMax[] PixelHelper_3BPP_Image() { IMinMax[] minMax = new IMinMax[_images3bpp.Count]; for (int i = 0; i < _images3bpp.Count; i++) minMax[i] = _images3bpp[i].MinMax(); return minMax; } [Benchmark] public IMinMax[] PixelHelper_4BPP_Image() { IMinMax[] minMax = new IMinMax[_images4bpp.Count]; for (int i = 0; i < _images4bpp.Count; i++) minMax[i] = _images4bpp[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(_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(_colors4bpp[i])); return minMax; } #endregion }