diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs
index 86dc13e91..7e8fac2b0 100644
--- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs
+++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs
@@ -1,7 +1,5 @@
-//
-// Copyright (c) James Jackson-South and contributors.
+// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-//
using System;
using System.Drawing;
@@ -9,90 +7,88 @@ using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
+using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
-using CoreSize = SixLabors.Primitives.Size;
-
namespace SixLabors.ImageSharp.Benchmarks
{
- using System.Threading.Tasks;
-
- using SixLabors.ImageSharp.Formats.Jpeg;
-
[Config(typeof(Config.ShortClr))]
- public class Resize : BenchmarkBase
+ public abstract class ResizeBenchmarkBase
{
- private readonly Configuration configuration = new Configuration(new JpegConfigurationModule());
+ protected readonly Configuration Configuration = new Configuration(new JpegConfigurationModule());
+
+ private Image sourceImage;
+
+ private Bitmap sourceBitmap;
+
+ public const int SourceSize = 2000;
- [Params(false, true)]
- public bool EnableParallelExecution { get; set; }
+ public const int DestSize = 400;
+
+ [Params(1/*, 4, 8*/)]
+ public int MaxDegreeOfParallelism { get; set; }
[GlobalSetup]
public void Setup()
{
- this.configuration.MaxDegreeOfParallelism =
- this.EnableParallelExecution ? Environment.ProcessorCount : 1;
+ this.Configuration.MaxDegreeOfParallelism = this.MaxDegreeOfParallelism;
+
+ this.sourceImage = new Image(this.Configuration, SourceSize, SourceSize);
+ this.sourceBitmap = new Bitmap(SourceSize, SourceSize);
+ }
+
+ [GlobalCleanup]
+ public void Cleanup()
+ {
+ this.sourceImage.Dispose();
+ this.sourceBitmap.Dispose();
}
- [Benchmark(Baseline = true, Description = "System.Drawing Resize")]
- public Size ResizeSystemDrawing()
+ [Benchmark(Baseline = true)]
+ public int SystemDrawing()
{
- using (Bitmap source = new Bitmap(2000, 2000))
+ using (var destination = new Bitmap(DestSize, DestSize))
{
- using (Bitmap destination = new Bitmap(400, 400))
+ using (var graphics = Graphics.FromImage(destination))
{
- using (Graphics graphics = Graphics.FromImage(destination))
- {
- graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
- graphics.CompositingQuality = CompositingQuality.HighQuality;
- graphics.DrawImage(source, 0, 0, 400, 400);
- }
-
- return destination.Size;
+ graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
+ graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
+ graphics.CompositingQuality = CompositingQuality.HighQuality;
+ graphics.DrawImage(this.sourceBitmap, 0, 0, DestSize, DestSize);
}
+
+ return destination.Width;
}
}
- [Benchmark(Description = "ImageSharp Resize")]
- public CoreSize ResizeCore()
+ [Benchmark]
+ public int ImageSharp()
{
- using (var image = new Image(this.configuration, 2000, 2000))
+ using (Image clone = this.sourceImage.Clone(this.ExecuteResizeOperation))
{
- image.Mutate(x => x.Resize(400, 400));
- return new CoreSize(image.Width, image.Height);
+ //Console.WriteLine($"{this.sourceImage.Width} -> {clone.Width} ?");
+ return clone.Width;
}
}
- //[Benchmark(Description = "ImageSharp Vector Resize")]
- //public CoreSize ResizeCoreVector()
- //{
- // using (Image image = new Image(2000, 2000))
- // {
- // image.Resize(400, 400);
- // return new CoreSize(image.Width, image.Height);
- // }
- //}
-
- //[Benchmark(Description = "ImageSharp Compand Resize")]
- //public CoreSize ResizeCoreCompand()
- //{
- // using (Image image = new Image(2000, 2000))
- // {
- // image.Resize(400, 400, true);
- // return new CoreSize(image.Width, image.Height);
- // }
- //}
-
- //[Benchmark(Description = "ImageSharp Vector Compand Resize")]
- //public CoreSize ResizeCoreVectorCompand()
- //{
- // using (Image image = new Image(2000, 2000))
- // {
- // image.Resize(400, 400, true);
- // return new CoreSize(image.Width, image.Height);
- // }
- //}
+ protected abstract void ExecuteResizeOperation(IImageProcessingContext ctx);
+ }
+
+ public class Resize_Bicubic : ResizeBenchmarkBase
+ {
+ protected override void ExecuteResizeOperation(IImageProcessingContext ctx)
+ {
+ //Console.WriteLine("wtf?");
+ ctx.Resize(DestSize, DestSize, KnownResamplers.Bicubic);
+ }
+ }
+
+ public class Resize_BicubicCompand : ResizeBenchmarkBase
+ {
+ protected override void ExecuteResizeOperation(IImageProcessingContext ctx)
+ {
+ ctx.Resize(DestSize, DestSize, KnownResamplers.Bicubic, true);
+ }
}
}