Browse Source

better profiler output for ResizeProcessor

af/merge-core
Anton Firszov 8 years ago
parent
commit
fc7eee8400
  1. 12
      src/ImageSharp/Common/Extensions/Vector4Extensions.cs
  2. 2
      src/ImageSharp/Common/Helpers/InliningOptions.cs
  3. 10
      src/ImageSharp/Processing/Processors/Transforms/ResizeKernel.cs
  4. 4
      tests/ImageSharp.Benchmarks/Samplers/Resize.cs
  5. 29
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs

12
src/ImageSharp/Common/Extensions/Vector4Extensions.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
/// <param name="source">The <see cref="Vector4"/> to premultiply</param> /// <param name="source">The <see cref="Vector4"/> to premultiply</param>
/// <returns>The <see cref="Vector4"/></returns> /// <returns>The <see cref="Vector4"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public static Vector4 Premultiply(this Vector4 source) public static Vector4 Premultiply(this Vector4 source)
{ {
float w = source.W; float w = source.W;
@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
/// <param name="source">The <see cref="Vector4"/> to premultiply</param> /// <param name="source">The <see cref="Vector4"/> to premultiply</param>
/// <returns>The <see cref="Vector4"/></returns> /// <returns>The <see cref="Vector4"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public static Vector4 UnPremultiply(this Vector4 source) public static Vector4 UnPremultiply(this Vector4 source)
{ {
float w = source.W; float w = source.W;
@ -86,7 +86,7 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
/// <param name="linear">The <see cref="Vector4"/> whose signal to compress.</param> /// <param name="linear">The <see cref="Vector4"/> whose signal to compress.</param>
/// <returns>The <see cref="Vector4"/>.</returns> /// <returns>The <see cref="Vector4"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public static Vector4 Compress(this Vector4 linear) public static Vector4 Compress(this Vector4 linear)
{ {
// TODO: Is there a faster way to do this? // TODO: Is there a faster way to do this?
@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
/// <param name="gamma">The <see cref="Rgba32"/> whose signal to expand.</param> /// <param name="gamma">The <see cref="Rgba32"/> whose signal to expand.</param>
/// <returns>The <see cref="Vector4"/>.</returns> /// <returns>The <see cref="Vector4"/>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public static Vector4 Expand(this Vector4 gamma) public static Vector4 Expand(this Vector4 gamma)
{ {
// TODO: Is there a faster way to do this? // TODO: Is there a faster way to do this?
@ -150,7 +150,7 @@ namespace SixLabors.ImageSharp
/// <returns> /// <returns>
/// The <see cref="float"/>. /// The <see cref="float"/>.
/// </returns> /// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private static float Compress(float signal) private static float Compress(float signal)
{ {
if (signal <= 0.0031308F) if (signal <= 0.0031308F)
@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp
/// <returns> /// <returns>
/// The <see cref="float"/>. /// The <see cref="float"/>.
/// </returns> /// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
private static float Expand(float signal) private static float Expand(float signal)
{ {
if (signal <= 0.04045F) if (signal <= 0.04045F)

2
src/ImageSharp/Common/Helpers/InliningOptions.cs

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// Uncomment this for verbose profiler results: // Uncomment this for verbose profiler results:
// #define PROFILING #define PROFILING
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp

10
src/ImageSharp/Processing/Processors/Transforms/ResizeKernel.cs

@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <param name="left">The local left index</param> /// <param name="left">The local left index</param>
/// <param name="buffer">The span</param> /// <param name="buffer">The span</param>
/// <param name="length">The length of the window</param> /// <param name="length">The length of the window</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
internal ResizeKernel(int index, int left, Buffer2D<float> buffer, int length) internal ResizeKernel(int index, int left, Buffer2D<float> buffer, int length)
{ {
this.flatStartIndex = index * buffer.Width; 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. /// Gets a reference to the first item of the window.
/// </summary> /// </summary>
/// <returns>The reference to the first item of the window</returns> /// <returns>The reference to the first item of the window</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public ref float GetStartReference() public ref float GetStartReference()
{ {
Span<float> span = this.buffer.Span; Span<float> span = this.buffer.Span;
@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// Gets the span representing the portion of the <see cref="KernelMap"/> that this window covers /// Gets the span representing the portion of the <see cref="KernelMap"/> that this window covers
/// </summary> /// </summary>
/// <returns>The <see cref="Span{T}"/></returns> /// <returns>The <see cref="Span{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public Span<float> GetSpan() => this.buffer.Span.Slice(this.flatStartIndex, this.Length); public Span<float> GetSpan() => this.buffer.Span.Slice(this.flatStartIndex, this.Length);
/// <summary> /// <summary>
@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <param name="rowSpan">The input span of vectors</param> /// <param name="rowSpan">The input span of vectors</param>
/// <param name="sourceX">The source row position.</param> /// <param name="sourceX">The source row position.</param>
/// <returns>The weighted sum</returns> /// <returns>The weighted sum</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public Vector4 Convolve(Span<Vector4> rowSpan, int sourceX) public Vector4 Convolve(Span<Vector4> rowSpan, int sourceX)
{ {
ref float horizontalValues = ref this.GetStartReference(); ref float horizontalValues = ref this.GetStartReference();
@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <param name="rowSpan">The input span of vectors</param> /// <param name="rowSpan">The input span of vectors</param>
/// <param name="sourceX">The source row position.</param> /// <param name="sourceX">The source row position.</param>
/// <returns>The weighted sum</returns> /// <returns>The weighted sum</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(InliningOptions.ShortMethod)]
public Vector4 ConvolveExpand(Span<Vector4> rowSpan, int sourceX) public Vector4 ConvolveExpand(Span<Vector4> rowSpan, int sourceX)
{ {
ref float horizontalValues = ref this.GetStartReference(); ref float horizontalValues = ref this.GetStartReference();

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

@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Benchmarks
public const int DestSize = 400; public const int DestSize = 400;
[Params(1/*, 4, 8*/)] [Params(1, 4, 8)]
public int MaxDegreeOfParallelism { get; set; } public int MaxDegreeOfParallelism { get; set; }
[GlobalSetup] [GlobalSetup]
@ -67,7 +67,6 @@ namespace SixLabors.ImageSharp.Benchmarks
{ {
using (Image<Rgba32> clone = this.sourceImage.Clone(this.ExecuteResizeOperation)) using (Image<Rgba32> clone = this.sourceImage.Clone(this.ExecuteResizeOperation))
{ {
//Console.WriteLine($"{this.sourceImage.Width} -> {clone.Width} ?");
return clone.Width; return clone.Width;
} }
} }
@ -79,7 +78,6 @@ namespace SixLabors.ImageSharp.Benchmarks
{ {
protected override void ExecuteResizeOperation(IImageProcessingContext<Rgba32> ctx) protected override void ExecuteResizeOperation(IImageProcessingContext<Rgba32> ctx)
{ {
//Console.WriteLine("wtf?");
ctx.Resize(DestSize, DestSize, KnownResamplers.Bicubic); ctx.Resize(DestSize, DestSize, KnownResamplers.Bicubic);
} }
} }

29
tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs

@ -1,15 +1,8 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using System.Text;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Transforms;
using SixLabors.Primitives;
using Xunit; using Xunit;
using Xunit.Abstractions; using Xunit.Abstractions;
@ -18,24 +11,34 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ {
public class ResizeProfilingBenchmarks : MeasureFixture 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) public ResizeProfilingBenchmarks(ITestOutputHelper output)
: base(output) : base(output)
{ {
this.configuration.MaxDegreeOfParallelism = 1;
} }
public int ExecutionCount { get; set; } = 50; public int ExecutionCount { get; set; } = 50;
// [Theory] // Benchmark, enable manually! [Theory(Skip = SkipText)]
// [InlineData(100, 100)] [InlineData(100, 100)]
// [InlineData(2000, 2000)] [InlineData(2000, 2000)]
public void ResizeBicubic(int width, int height) public void ResizeBicubic(int width, int height)
{ {
this.Measure(this.ExecutionCount, this.Measure(this.ExecutionCount,
() => () =>
{ {
using (var image = new Image<Rgba32>(width, height)) using (var image = new Image<Rgba32>(this.configuration, width, height))
{ {
image.Mutate(x => x.Resize(width / 4, height / 4)); image.Mutate(x => x.Resize(width / 5, height / 5));
} }
}); });
} }

Loading…
Cancel
Save