Browse Source

Nits - Benchmarks (#884)

* Update metadata names

* Use WithIterationCount

* Format Benchmark documents

* Update copyright assignment to Six Labors & Contributors

* Update deps

* React to Benchmark library update
af/merge-core
Jason Nelson 7 years ago
committed by James Jackson-South
parent
commit
d645b5599e
  1. 9
      tests/ImageSharp.Benchmarks/BenchmarkBase.cs
  2. 2
      tests/ImageSharp.Benchmarks/Codecs/DecodeBmp.cs
  3. 4
      tests/ImageSharp.Benchmarks/Codecs/DecodeFilteredPng.cs
  4. 1
      tests/ImageSharp.Benchmarks/Codecs/DecodePng.cs
  5. 4
      tests/ImageSharp.Benchmarks/Codecs/ImageBenchmarkTests.cs
  6. 40
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs
  7. 8
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs
  8. 18
      tests/ImageSharp.Benchmarks/Codecs/Jpeg/EncodeJpeg.cs
  9. 18
      tests/ImageSharp.Benchmarks/Codecs/MultiImageBenchmarkBase.cs
  10. 12
      tests/ImageSharp.Benchmarks/Color/ColorEquality.cs
  11. 14
      tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToCieLabConvert.cs
  12. 15
      tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToHunterLabConvert.cs
  13. 15
      tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToLmsConvert.cs
  14. 14
      tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToRgbConvert.cs
  15. 32
      tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs
  16. 15
      tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs
  17. 17
      tests/ImageSharp.Benchmarks/Config.cs
  18. 38
      tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs
  19. 51
      tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs
  20. 35
      tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs
  21. 26
      tests/ImageSharp.Benchmarks/Drawing/DrawText.cs
  22. 32
      tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs
  23. 49
      tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs
  24. 24
      tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs
  25. 28
      tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs
  26. 14
      tests/ImageSharp.Benchmarks/General/Array2D.cs
  27. 19
      tests/ImageSharp.Benchmarks/General/ArrayCopy.cs
  28. 14
      tests/ImageSharp.Benchmarks/General/ArrayReverse.cs
  29. 4
      tests/ImageSharp.Benchmarks/General/BasicMath/ClampInt32IntoByte.cs
  30. 5
      tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs
  31. 2
      tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs
  32. 10
      tests/ImageSharp.Benchmarks/General/Vector4Constants.cs
  33. 8
      tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs
  34. 12
      tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs
  35. 14
      tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs
  36. 9
      tests/ImageSharp.Benchmarks/General/Vectorization/Divide.cs
  37. 8
      tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs
  38. 10
      tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs
  39. 6
      tests/ImageSharp.Benchmarks/General/Vectorization/Multiply.cs
  40. 12
      tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs
  41. 11
      tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs
  42. 6
      tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
  43. 13
      tests/ImageSharp.Benchmarks/Program.cs
  44. 42
      tests/ImageSharp.Benchmarks/Samplers/Crop.cs
  45. 6
      tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs
  46. 13
      tests/ImageSharp.Benchmarks/Samplers/Glow.cs
  47. 1
      tests/ImageSharp.Benchmarks/Samplers/Resize.cs
  48. 5
      tests/ImageSharp.Benchmarks/Samplers/Rotate.cs
  49. 5
      tests/ImageSharp.Benchmarks/Samplers/Skew.cs

9
tests/ImageSharp.Benchmarks/BenchmarkBase.cs

@ -1,7 +1,8 @@
namespace SixLabors.ImageSharp.Benchmarks
{
using SixLabors.ImageSharp.Formats;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
namespace SixLabors.ImageSharp.Benchmarks
{
/// <summary>
/// The image benchmark base class.
/// </summary>
@ -15,4 +16,4 @@
// Add Image Formats
}
}
}
}

2
tests/ImageSharp.Benchmarks/Codecs/DecodeBmp.cs

@ -54,4 +54,4 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
}
}
}
}
}

4
tests/ImageSharp.Benchmarks/Codecs/DecodeFilteredPng.cs

@ -1,7 +1,5 @@
// <copyright file="DecodePng.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.IO;
using System.Runtime.CompilerServices;

1
tests/ImageSharp.Benchmarks/Codecs/DecodePng.cs

@ -11,7 +11,6 @@ using SDImage = System.Drawing.Image;
namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodePng : BenchmarkBase
{

4
tests/ImageSharp.Benchmarks/Codecs/ImageBenchmarkTests.cs

@ -1,7 +1,5 @@
// <copyright file="ImageBenchmarkTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// This file contains small, cheap and "unit test" benchmarks to test MultiImageBenchmarkBase.
// Need this because there are no real test cases for the common benchmark utility stuff.

40
tests/ImageSharp.Benchmarks/Codecs/Jpeg/BlockOperations/Block8x8F_CopyTo2x2.cs

@ -364,22 +364,30 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations
ref Vector4 dTopLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset));
ref Vector4 dBottomLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset + destStride));
var xyLeft = new Vector4(sLeft.X);
xyLeft.Z = sLeft.Y;
xyLeft.W = sLeft.Y;
var zwLeft = new Vector4(sLeft.Z);
zwLeft.Z = sLeft.W;
zwLeft.W = sLeft.W;
var xyRight = new Vector4(sRight.X);
xyRight.Z = sRight.Y;
xyRight.W = sRight.Y;
var zwRight = new Vector4(sRight.Z);
zwRight.Z = sRight.W;
zwRight.W = sRight.W;
var xyLeft = new Vector4(sLeft.X)
{
Z = sLeft.Y,
W = sLeft.Y
};
var zwLeft = new Vector4(sLeft.Z)
{
Z = sLeft.W,
W = sLeft.W
};
var xyRight = new Vector4(sRight.X)
{
Z = sRight.Y,
W = sRight.Y
};
var zwRight = new Vector4(sRight.Z)
{
Z = sRight.W,
W = sRight.W
};
dTopLeft = xyLeft;
Unsafe.Add(ref dTopLeft, 1) = zwLeft;
Unsafe.Add(ref dTopLeft, 2) = xyRight;

8
tests/ImageSharp.Benchmarks/Codecs/Jpeg/DecodeJpeg_ImageSpecific.cs

@ -5,6 +5,7 @@ using System.Drawing;
using System.IO;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Jobs;
using SixLabors.ImageSharp.Formats.Jpeg;
@ -26,8 +27,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
{
public Config()
{
// Uncomment if you want to use any of the diagnoser
this.Add(new BenchmarkDotNet.Diagnosers.MemoryDiagnoser());
this.Add(MemoryDiagnoser.Default);
}
public class ShortClr : Benchmarks.Config
@ -35,8 +35,8 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
public ShortClr()
{
this.Add(
//Job.Clr.WithLaunchCount(1).WithWarmupCount(2).WithTargetCount(3),
Job.Core.WithLaunchCount(1).WithWarmupCount(2).WithTargetCount(3)
//Job.Clr.WithLaunchCount(1).WithWarmupCount(2).WithIterationCount(3),
Job.Core.WithLaunchCount(1).WithWarmupCount(2).WithIterationCount(3)
);
}
}

18
tests/ImageSharp.Benchmarks/Codecs/Jpeg/EncodeJpeg.cs

@ -1,18 +1,16 @@
// <copyright file="EncodeJpeg.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using SixLabors.ImageSharp.PixelFormats;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
{
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using BenchmarkDotNet.Attributes;
using CoreImage = SixLabors.ImageSharp.Image;
public class EncodeJpeg : BenchmarkBase
@ -45,19 +43,19 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
[Benchmark(Baseline = true, Description = "System.Drawing Jpeg")]
public void JpegSystemDrawing()
{
using (var memoryStream = new MemoryStream())
using (var stream = new MemoryStream())
{
this.bmpDrawing.Save(memoryStream, ImageFormat.Jpeg);
this.bmpDrawing.Save(stream, ImageFormat.Jpeg);
}
}
[Benchmark(Description = "ImageSharp Jpeg")]
public void JpegCore()
{
using (var memoryStream = new MemoryStream())
using (var stream = new MemoryStream())
{
this.bmpCore.SaveAsJpeg(memoryStream);
this.bmpCore.SaveAsJpeg(stream);
}
}
}
}
}

18
tests/ImageSharp.Benchmarks/Codecs/MultiImageBenchmarkBase.cs

@ -1,7 +1,5 @@
// <copyright file="MultiImageBenchmarkBase.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
@ -18,7 +16,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using SixLabors.ImageSharp.Tests;
using CoreImage = ImageSharp.Image;
@ -30,7 +28,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
public Config()
{
// Uncomment if you want to use any of the diagnoser
this.Add(new BenchmarkDotNet.Diagnosers.MemoryDiagnoser());
this.Add(MemoryDiagnoser.Default);
}
public class ShortClr : Benchmarks.Config
@ -38,7 +36,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
public ShortClr()
{
this.Add(
Job.Core.WithLaunchCount(1).WithWarmupCount(1).WithTargetCount(2)
Job.Core.WithLaunchCount(1).WithWarmupCount(1).WithIterationCount(2)
);
}
}
@ -47,7 +45,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
protected Dictionary<string, byte[]> FileNamesToBytes = new Dictionary<string, byte[]>();
protected Dictionary<string, Image<Rgba32>> FileNamesToImageSharpImages = new Dictionary<string, Image<Rgba32>>();
protected Dictionary<string, System.Drawing.Bitmap> FileNamesToSystemDrawingImages = new Dictionary<string, System.Drawing.Bitmap>();
protected Dictionary<string, Bitmap> FileNamesToSystemDrawingImages = new Dictionary<string, System.Drawing.Bitmap>();
/// <summary>
/// The values of this enum separate input files into categories
@ -152,7 +150,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
foreach (KeyValuePair<string, byte[]> kv in this.FileNames2Bytes)
{
using (MemoryStream memoryStream = new MemoryStream(kv.Value))
using (var memoryStream = new MemoryStream(kv.Value))
{
try
{
@ -179,7 +177,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
byte[] bytes = kv.Value;
string fn = kv.Key;
using (MemoryStream ms1 = new MemoryStream(bytes))
using (var ms1 = new MemoryStream(bytes))
{
this.FileNamesToImageSharpImages[fn] = CoreImage.Load<Rgba32>(ms1);
@ -223,7 +221,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
protected void ForEachImageSharpImage(Func<Image<Rgba32>, MemoryStream, object> operation)
{
using (MemoryStream workStream = new MemoryStream())
using (var workStream = new MemoryStream())
{
this.ForEachImageSharpImage(

12
tests/ImageSharp.Benchmarks/Color/ColorEquality.cs

@ -1,14 +1,12 @@
// <copyright file="ColorEquality.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace SixLabors.ImageSharp.Benchmarks
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Benchmarks
{
using SystemColor = System.Drawing.Color;
public class ColorEquality

14
tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToCieLabConvert.cs

@ -1,13 +1,13 @@
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using Colourful;
using Colourful.Conversion;
using Colourful;
using Colourful.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
public class ColorspaceCieXyzToCieLabConvert
{
private static readonly CieXyz CieXyz = new CieXyz(0.95047F, 1, 1.08883F);

15
tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToHunterLabConvert.cs

@ -1,13 +1,13 @@
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using Colourful;
using Colourful.Conversion;
using Colourful;
using Colourful.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
public class ColorspaceCieXyzToHunterLabConvert
{
private static readonly CieXyz CieXyz = new CieXyz(0.95047F, 1, 1.08883F);
@ -18,7 +18,6 @@
private static readonly ColourfulConverter ColourfulConverter = new ColourfulConverter();
[Benchmark(Baseline = true, Description = "Colourful Convert")]
public double ColourfulConvert()
{

15
tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToLmsConvert.cs

@ -1,13 +1,13 @@
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using Colourful;
using Colourful.Conversion;
using Colourful;
using Colourful.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
public class ColorspaceCieXyzToLmsConvert
{
private static readonly CieXyz CieXyz = new CieXyz(0.95047F, 1, 1.08883F);
@ -18,7 +18,6 @@
private static readonly ColourfulConverter ColourfulConverter = new ColourfulConverter();
[Benchmark(Baseline = true, Description = "Colourful Convert")]
public double ColourfulConvert()
{

14
tests/ImageSharp.Benchmarks/Color/ColorspaceCieXyzToRgbConvert.cs

@ -1,13 +1,13 @@
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using Colourful;
using Colourful.Conversion;
using Colourful;
using Colourful.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
public class ColorspaceCieXyzToRgbConvert
{
private static readonly CieXyz CieXyz = new CieXyz(0.95047F, 1, 1.08883F);

32
tests/ImageSharp.Benchmarks/Color/RgbToYCbCr.cs

@ -136,7 +136,7 @@ namespace SixLabors.ImageSharp.Benchmarks
OnStackInputCache.Byte input = OnStackInputCache.Byte.Create(this.inputSourceRGB);
// On-stack output:
Result result = default(Result);
Result result = default;
float* yPtr = (float*)&result.Y;
float* cbPtr = (float*)&result.Cb;
float* crPtr = (float*)&result.Cr;
@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp.Benchmarks
OnStackInputCache.Byte input = OnStackInputCache.Byte.Create(this.inputSourceRGB);
// On-stack output:
Result result = default(Result);
Result result = default;
float* yPtr = (float*)&result.Y;
float* cbPtr = (float*)&result.Cb;
float* crPtr = (float*)&result.Cr;
@ -194,15 +194,15 @@ namespace SixLabors.ImageSharp.Benchmarks
// Copy the input to the stack:
// On-stack output:
Result result = default(Result);
Result result = default;
float* yPtr = (float*)&result.Y;
float* cbPtr = (float*)&result.Cb;
float* crPtr = (float*)&result.Cr;
// end of code-bloat block :)
Vector<int> yCoeffs = new Vector<int>(ScaledCoeffs.Y);
Vector<int> cbCoeffs = new Vector<int>(ScaledCoeffs.Cb);
Vector<int> crCoeffs = new Vector<int>(ScaledCoeffs.Cr);
var yCoeffs = new Vector<int>(ScaledCoeffs.Y);
var cbCoeffs = new Vector<int>(ScaledCoeffs.Cb);
var crCoeffs = new Vector<int>(ScaledCoeffs.Cr);
for (int i = 0; i < this.inputSourceRGB.Length; i++)
{
@ -240,23 +240,23 @@ namespace SixLabors.ImageSharp.Benchmarks
// Copy the input to the stack:
// On-stack output:
Result result = default(Result);
Result result = default;
float* yPtr = (float*)&result.Y;
float* cbPtr = (float*)&result.Cb;
float* crPtr = (float*)&result.Cr;
// end of code-bloat block :)
Vector<int> yCoeffs = new Vector<int>(ScaledCoeffs.Y);
Vector<int> cbCoeffs = new Vector<int>(ScaledCoeffs.Cb);
Vector<int> crCoeffs = new Vector<int>(ScaledCoeffs.Cr);
var yCoeffs = new Vector<int>(ScaledCoeffs.Y);
var cbCoeffs = new Vector<int>(ScaledCoeffs.Cb);
var crCoeffs = new Vector<int>(ScaledCoeffs.Cr);
Vector<int> leftY = new Vector<int>(ScaledCoeffs.SelectLeft.Y);
Vector<int> leftCb = new Vector<int>(ScaledCoeffs.SelectLeft.Cb);
Vector<int> leftCr = new Vector<int>(ScaledCoeffs.SelectLeft.Cr);
var leftY = new Vector<int>(ScaledCoeffs.SelectLeft.Y);
var leftCb = new Vector<int>(ScaledCoeffs.SelectLeft.Cb);
var leftCr = new Vector<int>(ScaledCoeffs.SelectLeft.Cr);
Vector<int> rightY = new Vector<int>(ScaledCoeffs.SelectRight.Y);
Vector<int> rightCb = new Vector<int>(ScaledCoeffs.SelectRight.Cb);
Vector<int> rightCr = new Vector<int>(ScaledCoeffs.SelectRight.Cr);
var rightY = new Vector<int>(ScaledCoeffs.SelectRight.Y);
var rightCb = new Vector<int>(ScaledCoeffs.SelectRight.Cb);
var rightCr = new Vector<int>(ScaledCoeffs.SelectRight.Cr);
for (int i = 0; i < this.inputSourceRGB.Length; i++)
{

15
tests/ImageSharp.Benchmarks/Color/RgbWorkingSpaceAdapt.cs

@ -1,13 +1,13 @@
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using Colourful;
using Colourful.Conversion;
using Colourful;
using Colourful.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
using SixLabors.ImageSharp.ColorSpaces;
using SixLabors.ImageSharp.ColorSpaces.Conversion;
namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces
{
public class RgbWorkingSpaceAdapt
{
private static readonly Rgb Rgb = new Rgb(0.206162F, 0.260277F, 0.746717F, RgbWorkingSpaces.WideGamutRgb);
@ -18,7 +18,6 @@
private static readonly ColourfulConverter ColourfulConverter = new ColourfulConverter { TargetRGBWorkingSpace = RGBWorkingSpaces.sRGB };
[Benchmark(Baseline = true, Description = "Colourful Adapt")]
public RGBColor ColourfulConvert()
{

17
tests/ImageSharp.Benchmarks/Config.cs

@ -1,20 +1,17 @@
// <copyright file="Config.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Jobs;
namespace SixLabors.ImageSharp.Benchmarks
{
using BenchmarkDotNet.Jobs;
public class Config : ManualConfig
{
public Config()
{
// Uncomment if you want to use any of the diagnoser
this.Add(new BenchmarkDotNet.Diagnosers.MemoryDiagnoser());
this.Add(MemoryDiagnoser.Default);
}
public class ShortClr : Config
@ -22,9 +19,9 @@ namespace SixLabors.ImageSharp.Benchmarks
public ShortClr()
{
this.Add(
Job.Clr.WithLaunchCount(1).WithWarmupCount(3).WithTargetCount(3),
Job.Core.WithLaunchCount(1).WithWarmupCount(3).WithTargetCount(3)
);
Job.Clr.WithLaunchCount(1).WithWarmupCount(3).WithIterationCount(3),
Job.Core.WithLaunchCount(1).WithWarmupCount(3).WithIterationCount(3)
);
}
}
}

38
tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs

@ -1,7 +1,5 @@
// <copyright file="DrawBeziers.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
@ -19,27 +17,25 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Baseline = true, Description = "System.Drawing Draw Beziers")]
public void DrawPathSystemDrawing()
{
using (Bitmap destination = new Bitmap(800, 800))
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (Graphics graphics = Graphics.FromImage(destination))
using (var pen = new Pen(Color.HotPink, 10))
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
{
graphics.DrawBeziers(pen, new[] {
new PointF(10, 500),
new PointF(30, 10),
new PointF(240, 30),
new PointF(300, 500)
});
}
graphics.DrawBeziers(pen, new[] {
new PointF(10, 500),
new PointF(30, 10),
new PointF(240, 30),
new PointF(300, 500)
});
}
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
destination.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
destination.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}
@ -47,7 +43,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Beziers")]
public void DrawLinesCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.DrawBeziers(
Rgba32.HotPink,
@ -59,9 +55,9 @@ namespace SixLabors.ImageSharp.Benchmarks
new Vector2(300, 500)
}));
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
image.SaveAsBmp(ms);
image.SaveAsBmp(stream);
}
}
}

51
tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs

@ -1,44 +1,41 @@
// <copyright file="DrawLines.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Numerics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp.Benchmarks
{
public class DrawLines : BenchmarkBase
{
[Benchmark(Baseline = true, Description = "System.Drawing Draw Lines")]
public void DrawPathSystemDrawing()
{
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
using (var graphics = Graphics.FromImage(destination))
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(Color.HotPink, 10))
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
{
graphics.DrawLines(pen, new[] {
new PointF(10, 10),
new PointF(550, 50),
new PointF(200, 400)
});
}
graphics.DrawLines(pen, new[] {
new PointF(10, 10),
new PointF(550, 50),
new PointF(200, 400)
});
}
using (var ms = new MemoryStream())
using (var stream = new MemoryStream())
{
destination.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
destination.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}
@ -57,9 +54,9 @@ namespace SixLabors.ImageSharp.Benchmarks
new Vector2(200, 400)
}));
using (var ms = new MemoryStream())
using (var stream = new MemoryStream())
{
image.SaveAsBmp(ms);
image.SaveAsBmp(stream);
}
}
}

35
tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs

@ -1,7 +1,5 @@
// <copyright file="Crop.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
@ -19,26 +17,23 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Baseline = true, Description = "System.Drawing Draw Polygon")]
public void DrawPolygonSystemDrawing()
{
using (Bitmap destination = new Bitmap(800, 800))
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
using (Graphics graphics = Graphics.FromImage(destination))
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(Color.HotPink, 10))
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
{
graphics.DrawPolygon(pen, new[] {
new PointF(10, 10),
new PointF(550, 50),
new PointF(200, 400)
});
}
graphics.DrawPolygon(pen, new[] {
new PointF(10, 10),
new PointF(550, 50),
new PointF(200, 400)
});
}
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
destination.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
destination.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}
@ -46,7 +41,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Polygon")]
public void DrawPolygonCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.DrawPolygon(
Rgba32.HotPink,
@ -57,7 +52,7 @@ namespace SixLabors.ImageSharp.Benchmarks
new Vector2(200, 400)
}));
using (MemoryStream ms = new MemoryStream())
using (var ms = new MemoryStream())
{
image.SaveAsBmp(ms);
}

26
tests/ImageSharp.Benchmarks/Drawing/DrawText.cs

@ -1,7 +1,5 @@
// <copyright file="Crop.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
@ -14,11 +12,9 @@ using SixLabors.ImageSharp.Processing.Processors.Text;
namespace SixLabors.ImageSharp.Benchmarks
{
[MemoryDiagnoser]
public class DrawText : BenchmarkBase
{
[Params(10, 100)]
public int TextIterations { get; set; }
public string TextPhrase { get; set; } = "Hello World";
@ -28,26 +24,22 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Baseline = true, Description = "System.Drawing Draw Text")]
public void DrawTextSystemDrawing()
{
using (Bitmap destination = new Bitmap(800, 800))
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
using (Graphics graphics = Graphics.FromImage(destination))
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var font = new Font("Arial", 12, GraphicsUnit.Point))
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var font = new Font("Arial", 12, GraphicsUnit.Point))
{
graphics.DrawString(TextToRender, font, System.Drawing.Brushes.HotPink, new RectangleF(10, 10, 780, 780));
}
graphics.DrawString(TextToRender, font, System.Drawing.Brushes.HotPink, new RectangleF(10, 10, 780, 780));
}
}
}
[Benchmark(Description = "ImageSharp Draw Text - Cached Glyphs")]
public void DrawTextCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12);
image.Mutate(x => x.ApplyProcessor(new DrawTextProcessor<Rgba32>(new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, Processing.Brushes.Solid(Rgba32.HotPink), null, new SixLabors.Primitives.PointF(10, 10))));
@ -57,7 +49,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Text - Nieve")]
public void DrawTextCoreOld()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12);
image.Mutate(x => DrawTextOldVersion(x, new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, Processing.Brushes.Solid(Rgba32.HotPink), null, new SixLabors.Primitives.PointF(10, 10)));

32
tests/ImageSharp.Benchmarks/Drawing/DrawTextOutline.cs

@ -1,7 +1,5 @@
// <copyright file="Crop.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
@ -13,34 +11,28 @@ using SixLabors.ImageSharp.Processing.Processors.Text;
namespace SixLabors.ImageSharp.Benchmarks
{
[MemoryDiagnoser]
public class DrawTextOutline : BenchmarkBase
{
[Params(10, 100)]
public int TextIterations { get; set; }
public string TextPhrase { get; set; } = "Hello World";
public string TextToRender => string.Join(" ", Enumerable.Repeat(TextPhrase, TextIterations));
[Benchmark(Baseline = true, Description = "System.Drawing Draw Text Outline")]
public void DrawTextSystemDrawing()
{
using (Bitmap destination = new Bitmap(800, 800))
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
using (Graphics graphics = Graphics.FromImage(destination))
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(Color.HotPink, 10))
using (var font = new Font("Arial", 12, GraphicsUnit.Point))
using (var gp = new GraphicsPath())
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var pen = new Pen(System.Drawing.Color.HotPink, 10))
using (var font = new Font("Arial", 12, GraphicsUnit.Point))
using (var gp = new GraphicsPath())
{
gp.AddString(TextToRender, font.FontFamily, (int)font.Style, font.Size, new RectangleF(10, 10, 780, 780), new StringFormat());
graphics.DrawPath(pen, gp);
}
gp.AddString(TextToRender, font.FontFamily, (int)font.Style, font.Size, new RectangleF(10, 10, 780, 780), new StringFormat());
graphics.DrawPath(pen, gp);
}
}
}
@ -48,7 +40,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Text Outline - Cached Glyphs")]
public void DrawTextCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12);
image.Mutate(x => x.ApplyProcessor(new DrawTextProcessor<Rgba32>(new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, Processing.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10))));
@ -58,7 +50,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Draw Text Outline - Nieve")]
public void DrawTextCoreOld()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 12);
image.Mutate(x => DrawTextOldVersion(x, new TextGraphicsOptions(true) { WrapTextWidth = 780 }, TextToRender, font, null, Processing.Pens.Solid(Rgba32.HotPink, 10), new SixLabors.Primitives.PointF(10, 10)));

49
tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs

@ -1,7 +1,5 @@
// <copyright file="FillPolygon.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
@ -21,31 +19,30 @@ namespace SixLabors.ImageSharp.Benchmarks
public FillPolygon()
{
this.shape = new Polygon(new LinearLineSegment(new Vector2(10, 10),
new Vector2(550, 50),
new Vector2(200, 400)));
this.shape = new Polygon(new LinearLineSegment(
new Vector2(10, 10),
new Vector2(550, 50),
new Vector2(200, 400)));
}
[Benchmark(Baseline = true, Description = "System.Drawing Fill Polygon")]
public void DrawSolidPolygonSystemDrawing()
{
using (Bitmap destination = new Bitmap(800, 800))
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.FillPolygon(System.Drawing.Brushes.HotPink,
new[] {
new Point(10, 10),
new Point(550, 50),
new Point(200, 400)
});
using (Graphics graphics = Graphics.FromImage(destination))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.FillPolygon(System.Drawing.Brushes.HotPink,
new[]
{
new Point(10, 10),
new Point(550, 50),
new Point(200, 400)
});
}
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
destination.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
destination.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}
@ -53,7 +50,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Polygon")]
public void DrawSolidPolygonCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.FillPolygon(
Rgba32.HotPink,
@ -63,9 +60,9 @@ namespace SixLabors.ImageSharp.Benchmarks
new Vector2(200, 400)
}));
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
image.SaveAsBmp(ms);
image.SaveAsBmp(stream);
}
}
}
@ -73,15 +70,15 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Polygon - cached shape")]
public void DrawSolidPolygonCoreCahced()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.Fill(
Rgba32.HotPink,
this.shape));
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
image.SaveAsBmp(ms);
image.SaveAsBmp(stream);
}
}
}

24
tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs

@ -1,7 +1,5 @@
// <copyright file="Crop.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
@ -15,22 +13,18 @@ using CoreSize = SixLabors.Primitives.Size;
namespace SixLabors.ImageSharp.Benchmarks
{
public class FillRectangle : BenchmarkBase
{
[Benchmark(Baseline = true, Description = "System.Drawing Fill Rectangle")]
public Size FillRectangleSystemDrawing()
{
using (Bitmap destination = new Bitmap(800, 800))
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
using (Graphics graphics = Graphics.FromImage(destination))
{
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.FillRectangle(System.Drawing.Brushes.HotPink, new Rectangle(10, 10, 190, 140));
}
graphics.InterpolationMode = InterpolationMode.Default;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.FillRectangle(System.Drawing.Brushes.HotPink, new Rectangle(10, 10, 190, 140));
return destination.Size;
}
}
@ -38,7 +32,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Rectangle")]
public CoreSize FillRactangleCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140)));
@ -49,7 +43,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill Rectangle - As Polygon")]
public CoreSize FillPolygonCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.FillPolygon(
Rgba32.HotPink,

28
tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs

@ -1,7 +1,5 @@
// <copyright file="FillWithPattern.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
@ -21,19 +19,19 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Baseline = true, Description = "System.Drawing Fill with Pattern")]
public void DrawPatternPolygonSystemDrawing()
{
using (Bitmap destination = new Bitmap(800, 800))
using (var destination = new Bitmap(800, 800))
using (var graphics = Graphics.FromImage(destination))
{
using (Graphics graphics = Graphics.FromImage(destination))
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var brush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.HotPink))
{
graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (var brush = new HatchBrush(HatchStyle.BackwardDiagonal, Color.HotPink))
{
graphics.FillRectangle(brush, new Rectangle(0, 0, 800, 800)); // can't find a way to flood fill with a brush
}
graphics.FillRectangle(brush, new Rectangle(0, 0, 800, 800)); // can't find a way to flood fill with a brush
}
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
destination.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
destination.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
}
}
}
@ -41,13 +39,13 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Fill with Pattern")]
public void DrawPatternPolygon3Core()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink)));
using (MemoryStream ms = new MemoryStream())
using (var stream = new MemoryStream())
{
image.SaveAsBmp(ms);
image.SaveAsBmp(stream);
}
}
}

14
tests/ImageSharp.Benchmarks/General/Array2D.cs

@ -1,16 +1,14 @@
// <copyright file="Array2D.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace SixLabors.ImageSharp.Benchmarks.General
{
using System;
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Benchmarks.General
{
/**
* Method | Count | Mean | Error | StdDev | Scaled | ScaledSD |
-------------------------------------------- |------ |---------:|---------:|---------:|-------:|---------:|

19
tests/ImageSharp.Benchmarks/General/ArrayCopy.cs

@ -1,15 +1,14 @@
// <copyright file="ArrayCopy.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace SixLabors.ImageSharp.Benchmarks.General
{
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General
{
[Config(typeof(Config.ShortClr))]
public class ArrayCopy
{

14
tests/ImageSharp.Benchmarks/General/ArrayReverse.cs

@ -1,14 +1,12 @@
// <copyright file="ArrayReverse.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace SixLabors.ImageSharp.Benchmarks.General
{
using System;
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General
{
public class ArrayReverse
{
[Params(4, 16, 32)]
@ -58,4 +56,4 @@ namespace SixLabors.ImageSharp.Benchmarks.General
}
}
}
}
}

4
tests/ImageSharp.Benchmarks/General/BasicMath/ClampInt32IntoByte.cs

@ -1,7 +1,5 @@
// <copyright file="Clamp.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System;
using System.Runtime.CompilerServices;

5
tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToRgba32.cs

@ -1,7 +1,4 @@
// ReSharper disable InconsistentNaming
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;

2
tests/ImageSharp.Benchmarks/General/PixelConversion/PixelConversion_ConvertToVector4.cs

@ -3,8 +3,6 @@ using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Benchmarks.General.PixelConversion
{
public class PixelConversion_ConvertToVector4

10
tests/ImageSharp.Benchmarks/General/Vector4Constants.cs

@ -1,10 +1,10 @@
namespace SixLabors.ImageSharp.Benchmarks.General
{
using System;
using System.Numerics;
using System;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General
{
/// <summary>
/// Has it any effect on performance to store SIMD constants as static readonly fields? Is it OK to always inline them?
/// Spoiler: the difference seems to be statistically insignificant!

8
tests/ImageSharp.Benchmarks/General/Vectorization/BitwiseOrUint32.cs

@ -1,9 +1,9 @@
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
public class BitwiseOrUInt32
{
private uint[] input;

12
tests/ImageSharp.Benchmarks/General/Vectorization/DivFloat.cs

@ -1,9 +1,9 @@
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
public class DivFloat
{
private float[] input;
@ -41,11 +41,11 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
[Benchmark]
public void Simd()
{
Vector<float> v = new Vector<float>(this.testValue);
var v = new Vector<float>(this.testValue);
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<float> a = new Vector<float>(this.input, i);
var a = new Vector<float>(this.input, i);
a = a / v;
a.CopyTo(this.result, i);
}

14
tests/ImageSharp.Benchmarks/General/Vectorization/DivUInt32.cs

@ -1,9 +1,9 @@
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
public class DivUInt32
{
private uint[] input;
@ -32,6 +32,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
public void Standard()
{
uint v = this.testValue;
for (int i = 0; i < this.input.Length; i++)
{
this.result[i] = this.input[i] / v;
@ -41,11 +42,12 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
[Benchmark]
public void Simd()
{
Vector<uint> v = new Vector<uint>(this.testValue);
var v = new Vector<uint>(this.testValue);
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{
Vector<uint> a = new Vector<uint>(this.input, i);
var a = new Vector<uint>(this.input, i);
a = a / v;
a.CopyTo(this.result, i);
}

9
tests/ImageSharp.Benchmarks/General/Vectorization/Divide.cs

@ -1,10 +1,9 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System;
using System.Numerics;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace ImageSharp.Benchmarks.General.Vectorization
{
public class DivFloat : SIMDBenchmarkBase<float>.Divide
{
protected override float GetTestValue() => 42;

8
tests/ImageSharp.Benchmarks/General/Vectorization/MulFloat.cs

@ -1,9 +1,9 @@
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
public class MulFloat
{
private float[] input;

10
tests/ImageSharp.Benchmarks/General/Vectorization/MulUInt32.cs

@ -1,9 +1,9 @@
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
public class MulUInt32
{
private uint[] input;
@ -41,7 +41,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
[Benchmark]
public void Simd()
{
Vector<uint> v = new Vector<uint>(this.testValue);
var v = new Vector<uint>(this.testValue);
for (int i = 0; i < this.input.Length; i += Vector<uint>.Count)
{

6
tests/ImageSharp.Benchmarks/General/Vectorization/Multiply.cs

@ -1,8 +1,8 @@
using System.Numerics;
using BenchmarkDotNet.Attributes;
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using BenchmarkDotNet.Attributes;
public class MulUInt32 : SIMDBenchmarkBase<uint>.Multiply
{
protected override uint GetTestValue() => 42u;

12
tests/ImageSharp.Benchmarks/General/Vectorization/ReinterpretUInt32AsFloat.cs

@ -1,10 +1,10 @@
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Runtime.InteropServices;
using System.Numerics;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
{
public class ReinterpretUInt32AsFloat
{
private uint[] input;
@ -40,7 +40,7 @@ namespace SixLabors.ImageSharp.Benchmarks.General.Vectorization
[Benchmark(Baseline = true)]
public void Standard()
{
UIntFloatUnion u = default(UIntFloatUnion);
UIntFloatUnion u = default;
for (int i = 0; i < this.input.Length; i++)
{
u.i = this.input[i];

11
tests/ImageSharp.Benchmarks/General/Vectorization/SIMDBenchmarkBase.cs

@ -1,10 +1,10 @@
namespace ImageSharp.Benchmarks.General.Vectorization
{
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Numerics;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes;
namespace ImageSharp.Benchmarks.General.Vectorization
{
public abstract class SIMDBenchmarkBase<T>
where T : struct
{
@ -19,7 +19,6 @@ namespace ImageSharp.Benchmarks.General.Vectorization
protected virtual T GetTestValue() => default(T);
protected virtual Vector<T> GetTestVector() => new Vector<T>(this.GetTestValue());
[Params(32)]
public int InputSize { get; set; }

6
tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

@ -16,10 +16,10 @@
<Compile Include="..\ImageSharp.Tests\TestUtilities\TestEnvironment.cs" Link="Tests\TestEnvironment.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.11.3" />
<PackageReference Include="Colourful" Version="2.0.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.11.5" />
<PackageReference Include="Colourful" Version="2.0.2" />
<PackageReference Include="SixLabors.Shapes.Text" Version="1.0.0-beta0007" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ImageSharp.Drawing\ImageSharp.Drawing.csproj" />

13
tests/ImageSharp.Benchmarks/Program.cs

@ -1,15 +1,12 @@
// <copyright file="Program.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Reflection;
using BenchmarkDotNet.Running;
namespace SixLabors.ImageSharp.Benchmarks
{
using BenchmarkDotNet.Running;
using SixLabors.ImageSharp.Formats;
using System.Reflection;
public class Program
{
/// <summary>

42
tests/ImageSharp.Benchmarks/Samplers/Crop.cs

@ -1,46 +1,40 @@
// <copyright file="Crop.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Processing;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Processing;
using CoreSize = SixLabors.Primitives.Size;
using CoreSize = SixLabors.Primitives.Size;
namespace SixLabors.ImageSharp.Benchmarks
{
public class Crop : BenchmarkBase
{
[Benchmark(Baseline = true, Description = "System.Drawing Crop")]
public Size CropSystemDrawing()
{
using (Bitmap source = new Bitmap(800, 800))
using (var source = new Bitmap(800, 800))
using (var destination = new Bitmap(100, 100))
using (var graphics = Graphics.FromImage(destination))
{
using (Bitmap destination = new Bitmap(100, 100))
{
using (Graphics graphics = Graphics.FromImage(destination))
{
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.DrawImage(source, new Rectangle(0, 0, 100, 100), 0, 0, 100, 100, GraphicsUnit.Pixel);
}
return destination.Size;
}
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.DrawImage(source, new Rectangle(0, 0, 100, 100), 0, 0, 100, 100, GraphicsUnit.Pixel);
return destination.Size;
}
}
[Benchmark(Description = "ImageSharp Crop")]
public CoreSize CropResizeCore()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
image.Mutate(x => x.Crop(100, 100));
return new CoreSize(image.Width, image.Height);

6
tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs

@ -1,7 +1,5 @@
// <copyright file="DetectEdges.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
using SixLabors.ImageSharp.PixelFormats;
@ -53,4 +51,4 @@ namespace SixLabors.ImageSharp.Benchmarks
this.image.Mutate(x => x.DetectEdges(EdgeDetectionOperators.Sobel));
}
}
}
}

13
tests/ImageSharp.Benchmarks/Samplers/Glow.cs

@ -4,7 +4,6 @@
using System;
using System.Buffers;
using System.Numerics;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
@ -35,7 +34,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Glow - Bulk")]
public CoreSize GlowBulk()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
this.bulk.Apply(image, image.Bounds());
return new CoreSize(image.Width, image.Height);
@ -45,7 +44,7 @@ namespace SixLabors.ImageSharp.Benchmarks
[Benchmark(Description = "ImageSharp Glow - Parallel")]
public CoreSize GLowSimple()
{
using (Image<Rgba32> image = new Image<Rgba32>(800, 800))
using (var image = new Image<Rgba32>(800, 800))
{
this.parallel.Apply(image, image.Bounds());
return new CoreSize(image.Width, image.Height);
@ -128,7 +127,7 @@ namespace SixLabors.ImageSharp.Benchmarks
int offsetX = x - startX;
float distance = Vector2.Distance(centre, new Vector2(offsetX, offsetY));
Vector4 sourceColor = sourcePixels[offsetX, offsetY].ToVector4();
TPixel packed = default(TPixel);
TPixel packed = default;
packed.FromVector4(
PremultipliedLerp(
sourceColor,
@ -166,9 +165,9 @@ namespace SixLabors.ImageSharp.Benchmarks
// https://en.wikipedia.org/wiki/Alpha_compositing
// Vout = Vs + Vb (1 - Vsa)
// Aout = Vsa + Vsb (1 - Vsa)
Vector3 inverseW = new Vector3(1 - source.W);
Vector3 xyzB = new Vector3(backdrop.X, backdrop.Y, backdrop.Z);
Vector3 xyzS = new Vector3(source.X, source.Y, source.Z);
var inverseW = new Vector3(1 - source.W);
var xyzB = new Vector3(backdrop.X, backdrop.Y, backdrop.Z);
var xyzS = new Vector3(source.X, source.Y, source.Z);
return new Vector4(xyzS + (xyzB * inverseW), source.W + (backdrop.W * (1 - source.W)));
}

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

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

5
tests/ImageSharp.Benchmarks/Samplers/Rotate.cs

@ -1,4 +1,7 @@
using BenchmarkDotNet.Attributes;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;

5
tests/ImageSharp.Benchmarks/Samplers/Skew.cs

@ -1,4 +1,7 @@
using BenchmarkDotNet.Attributes;
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;

Loading…
Cancel
Save