Browse Source

WIP better Resize benchmarks

af/merge-core
Anton Firszov 8 years ago
parent
commit
3de0b1ad44
  1. 120
      tests/ImageSharp.Benchmarks/Samplers/Resize.cs

120
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;
private Bitmap sourceBitmap;
public const int SourceSize = 2000;
[Params(false, true)] public const int DestSize = 400;
public bool EnableParallelExecution { get; set; }
[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);
}
[GlobalCleanup]
public void Cleanup()
{
this.sourceImage.Dispose();
this.sourceBitmap.Dispose();
} }
[Benchmark(Baseline = true, Description = "System.Drawing Resize")] [Benchmark(Baseline = true)]
public Size ResizeSystemDrawing() 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.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.DrawImage(this.sourceBitmap, 0, 0, DestSize, DestSize);
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.DrawImage(source, 0, 0, 400, 400);
}
return destination.Size;
} }
return destination.Width;
} }
} }
[Benchmark(Description = "ImageSharp Resize")] [Benchmark]
public CoreSize ResizeCore() public int ImageSharp()
{ {
using (var image = new Image<Rgba32>(this.configuration, 2000, 2000)) using (Image<Rgba32> clone = this.sourceImage.Clone(this.ExecuteResizeOperation))
{ {
image.Mutate(x => x.Resize(400, 400)); //Console.WriteLine($"{this.sourceImage.Width} -> {clone.Width} ?");
return new CoreSize(image.Width, image.Height); return clone.Width;
} }
} }
//[Benchmark(Description = "ImageSharp Vector Resize")] protected abstract void ExecuteResizeOperation(IImageProcessingContext<Rgba32> ctx);
//public CoreSize ResizeCoreVector() }
//{
// using (Image<RgbaVector> image = new Image<RgbaVector>(2000, 2000)) public class Resize_Bicubic : ResizeBenchmarkBase
// { {
// image.Resize(400, 400); protected override void ExecuteResizeOperation(IImageProcessingContext<Rgba32> ctx)
// return new CoreSize(image.Width, image.Height); {
// } //Console.WriteLine("wtf?");
//} ctx.Resize(DestSize, DestSize, KnownResamplers.Bicubic);
}
//[Benchmark(Description = "ImageSharp Compand Resize")] }
//public CoreSize ResizeCoreCompand()
//{ public class Resize_BicubicCompand : ResizeBenchmarkBase
// using (Image<Rgba32> image = new Image<Rgba32>(2000, 2000)) {
// { protected override void ExecuteResizeOperation(IImageProcessingContext<Rgba32> ctx)
// image.Resize(400, 400, true); {
// return new CoreSize(image.Width, image.Height); ctx.Resize(DestSize, DestSize, KnownResamplers.Bicubic, true);
// } }
//}
//[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