Improved performance of Sum on Images

This commit is contained in:
DarthAffe committed 2024-08-19 22:19:25 +02:00
1 parent 723649053c
commit f4c1eaddd6
15 files changed
+103 -71

No files matched your search

+14
View File
@@ -21,4 +21,18 @@ internal static class BenchmarkHelper
return colors;
}
public static List<IImage<T>> GetSampleDataImages<T>()
where T : struct, IColor
{
if (!Directory.Exists(SAMPLE_DATA_DIR)) throw new Exception("sample data not found!");
List<IImage<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>());
return colors;
}
}
+25
View File
@@ -13,6 +13,8 @@ public class SumBenchmarks
private readonly List<ColorRGB[]> _colors3bpp;
private readonly List<ColorRGBA[]> _colors4bpp;
private readonly List<IImage<ColorRGB>> _images3bpp;
private readonly List<IImage<ColorRGBA>> _images4bpp;
#endregion
@@ -22,6 +24,9 @@ public class SumBenchmarks
{
_colors3bpp = BenchmarkHelper.GetSampleData<ColorRGB>();
_colors4bpp = BenchmarkHelper.GetSampleData<ColorRGBA>();
_images3bpp = BenchmarkHelper.GetSampleDataImages<ColorRGB>();
_images4bpp = BenchmarkHelper.GetSampleDataImages<ColorRGBA>();
}
#endregion
@@ -48,6 +53,26 @@ public class SumBenchmarks
return sums;
}
[Benchmark]
public ISum[] PixelHelper_3BPP_Image()
{
ISum[] sums = new ISum[_colors3bpp.Count];
for (int i = 0; i < _images3bpp.Count; i++)
sums[i] = _images3bpp[i].Sum();
return sums;
}
[Benchmark]
public ISum[] PixelHelper_4BPP_Image()
{
ISum[] sums = new ISum[_images4bpp.Count];
for (int i = 0; i < _images4bpp.Count; i++)
sums[i] = _images4bpp[i].Sum();
return sums;
}
[Benchmark]
public ISum[] Reference_3BPP()
{