diff --git a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs index 8dc9c96a0..f9bbdfc04 100644 --- a/src/ImageSharp/Common/Extensions/Vector4Extensions.cs +++ b/src/ImageSharp/Common/Extensions/Vector4Extensions.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp /// /// The to premultiply /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static Vector4 Premultiply(this Vector4 source) { float w = source.W; @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp /// /// The to premultiply /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static Vector4 UnPremultiply(this Vector4 source) { float w = source.W; @@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp /// /// The whose signal to compress. /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static Vector4 Compress(this Vector4 linear) { // TODO: Is there a faster way to do this? @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp /// /// The whose signal to expand. /// The . - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public static Vector4 Expand(this Vector4 gamma) { // TODO: Is there a faster way to do this? @@ -150,7 +150,7 @@ namespace SixLabors.ImageSharp /// /// The . /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] private static float Compress(float signal) { if (signal <= 0.0031308F) @@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp /// /// The . /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] private static float Expand(float signal) { if (signal <= 0.04045F) diff --git a/src/ImageSharp/Common/Helpers/InliningOptions.cs b/src/ImageSharp/Common/Helpers/InliningOptions.cs index e1d51da8d..9356abeb9 100644 --- a/src/ImageSharp/Common/Helpers/InliningOptions.cs +++ b/src/ImageSharp/Common/Helpers/InliningOptions.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. // Uncomment this for verbose profiler results: -// #define PROFILING +#define PROFILING using System.Runtime.CompilerServices; namespace SixLabors.ImageSharp diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeKernel.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeKernel.cs index eeb4aef19..902f6a1c0 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeKernel.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeKernel.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The local left index /// The span /// The length of the window - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] internal ResizeKernel(int index, int left, Buffer2D buffer, int length) { this.flatStartIndex = index * buffer.Width; @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// Gets a reference to the first item of the window. /// /// The reference to the first item of the window - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public ref float GetStartReference() { Span span = this.buffer.Span; @@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// Gets the span representing the portion of the that this window covers /// /// The - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Span GetSpan() => this.buffer.Span.Slice(this.flatStartIndex, this.Length); /// @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The input span of vectors /// The source row position. /// The weighted sum - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Vector4 Convolve(Span rowSpan, int sourceX) { ref float horizontalValues = ref this.GetStartReference(); @@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The input span of vectors /// The source row position. /// The weighted sum - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(InliningOptions.ShortMethod)] public Vector4 ConvolveExpand(Span rowSpan, int sourceX) { ref float horizontalValues = ref this.GetStartReference(); diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 7e8fac2b0..0cea9245a 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Benchmarks public const int DestSize = 400; - [Params(1/*, 4, 8*/)] + [Params(1, 4, 8)] public int MaxDegreeOfParallelism { get; set; } [GlobalSetup] @@ -67,7 +67,6 @@ namespace SixLabors.ImageSharp.Benchmarks { using (Image clone = this.sourceImage.Clone(this.ExecuteResizeOperation)) { - //Console.WriteLine($"{this.sourceImage.Width} -> {clone.Width} ?"); return clone.Width; } } @@ -79,7 +78,6 @@ namespace SixLabors.ImageSharp.Benchmarks { protected override void ExecuteResizeOperation(IImageProcessingContext ctx) { - //Console.WriteLine("wtf?"); ctx.Resize(DestSize, DestSize, KnownResamplers.Bicubic); } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs index f0062d714..9dde8c9cf 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs @@ -1,15 +1,8 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using System; -using System.IO; -using System.Text; - using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Processors.Transforms; - -using SixLabors.Primitives; using Xunit; using Xunit.Abstractions; @@ -18,24 +11,34 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms { public class ResizeProfilingBenchmarks : MeasureFixture { + public const string SkipText = +#if true + null; +#else + "Benchmark, enable manually"! +#endif + + private readonly Configuration configuration = Configuration.CreateDefaultInstance(); + public ResizeProfilingBenchmarks(ITestOutputHelper output) : base(output) { + this.configuration.MaxDegreeOfParallelism = 1; } public int ExecutionCount { get; set; } = 50; - - // [Theory] // Benchmark, enable manually! - // [InlineData(100, 100)] - // [InlineData(2000, 2000)] + + [Theory(Skip = SkipText)] + [InlineData(100, 100)] + [InlineData(2000, 2000)] public void ResizeBicubic(int width, int height) { this.Measure(this.ExecutionCount, () => { - using (var image = new Image(width, height)) + using (var image = new Image(this.configuration, width, height)) { - image.Mutate(x => x.Resize(width / 4, height / 4)); + image.Mutate(x => x.Resize(width / 5, height / 5)); } }); }