Browse Source

WIP better Resize benchmarks

pull/731/head
Anton Firszov 8 years ago
parent
commit
e7bb01b62b
  1. 108
      tests/ImageSharp.Benchmarks/Samplers/Resize.cs

108
tests/ImageSharp.Benchmarks/Samplers/Resize.cs

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

Loading…
Cancel
Save