Skip to content

Commit e9b9e27

Browse files
iamcarbonJimBobSquarePants
authored andcommitted
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
1 parent 45edceb commit e9b9e27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+352
-418
lines changed

tests/ImageSharp.Benchmarks/BenchmarkBase.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
namespace SixLabors.ImageSharp.Benchmarks
2-
{
3-
using SixLabors.ImageSharp.Formats;
1+
// Copyright (c) Six Labors and contributors.
2+
// Licensed under the Apache License, Version 2.0.
43

4+
namespace SixLabors.ImageSharp.Benchmarks
5+
{
56
/// <summary>
67
/// The image benchmark base class.
78
/// </summary>
@@ -15,4 +16,4 @@ protected BenchmarkBase()
1516
// Add Image Formats
1617
}
1718
}
18-
}
19+
}

tests/ImageSharp.Benchmarks/Codecs/DecodeBmp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ public CoreSize BmpCore()
5454
}
5555
}
5656
}
57-
}
57+
}

tests/ImageSharp.Benchmarks/Codecs/DecodeFilteredPng.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// <copyright file="DecodePng.cs" company="James Jackson-South">
2-
// Copyright (c) James Jackson-South and contributors.
1+
// Copyright (c) Six Labors and contributors.
32
// Licensed under the Apache License, Version 2.0.
4-
// </copyright>
53

64
using System.IO;
75
using System.Runtime.CompilerServices;

tests/ImageSharp.Benchmarks/Codecs/DecodePng.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace SixLabors.ImageSharp.Benchmarks.Codecs
1313
{
14-
1514
[Config(typeof(Config.ShortClr))]
1615
public class DecodePng : BenchmarkBase
1716
{

tests/ImageSharp.Benchmarks/Codecs/ImageBenchmarkTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// <copyright file="ImageBenchmarkTests.cs" company="James Jackson-South">
2-
// Copyright (c) James Jackson-South and contributors.
1+
// Copyright (c) Six Labors and contributors.
32
// Licensed under the Apache License, Version 2.0.
4-
// </copyright>
53

64
// This file contains small, cheap and "unit test" benchmarks to test MultiImageBenchmarkBase.
75
// Need this because there are no real test cases for the common benchmark utility stuff.

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -364,22 +364,30 @@ private static void WidenCopyImpl2x2_Vector4_V2(ref Block8x8F src, ref Vector2 d
364364
ref Vector4 dTopLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset));
365365
ref Vector4 dBottomLeft = ref Unsafe.As<Vector2, Vector4>(ref Unsafe.Add(ref destBase, offset + destStride));
366366

367-
var xyLeft = new Vector4(sLeft.X);
368-
xyLeft.Z = sLeft.Y;
369-
xyLeft.W = sLeft.Y;
370-
371-
var zwLeft = new Vector4(sLeft.Z);
372-
zwLeft.Z = sLeft.W;
373-
zwLeft.W = sLeft.W;
374-
375-
var xyRight = new Vector4(sRight.X);
376-
xyRight.Z = sRight.Y;
377-
xyRight.W = sRight.Y;
378-
379-
var zwRight = new Vector4(sRight.Z);
380-
zwRight.Z = sRight.W;
381-
zwRight.W = sRight.W;
382-
367+
var xyLeft = new Vector4(sLeft.X)
368+
{
369+
Z = sLeft.Y,
370+
W = sLeft.Y
371+
};
372+
373+
var zwLeft = new Vector4(sLeft.Z)
374+
{
375+
Z = sLeft.W,
376+
W = sLeft.W
377+
};
378+
379+
var xyRight = new Vector4(sRight.X)
380+
{
381+
Z = sRight.Y,
382+
W = sRight.Y
383+
};
384+
385+
var zwRight = new Vector4(sRight.Z)
386+
{
387+
Z = sRight.W,
388+
W = sRight.W
389+
};
390+
383391
dTopLeft = xyLeft;
384392
Unsafe.Add(ref dTopLeft, 1) = zwLeft;
385393
Unsafe.Add(ref dTopLeft, 2) = xyRight;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using BenchmarkDotNet.Attributes;
77
using BenchmarkDotNet.Configs;
8+
using BenchmarkDotNet.Diagnosers;
89
using BenchmarkDotNet.Jobs;
910

1011
using SixLabors.ImageSharp.Formats.Jpeg;
@@ -26,17 +27,16 @@ public class Config : ManualConfig
2627
{
2728
public Config()
2829
{
29-
// Uncomment if you want to use any of the diagnoser
30-
this.Add(new BenchmarkDotNet.Diagnosers.MemoryDiagnoser());
30+
this.Add(MemoryDiagnoser.Default);
3131
}
3232

3333
public class ShortClr : Benchmarks.Config
3434
{
3535
public ShortClr()
3636
{
3737
this.Add(
38-
//Job.Clr.WithLaunchCount(1).WithWarmupCount(2).WithTargetCount(3),
39-
Job.Core.WithLaunchCount(1).WithWarmupCount(2).WithTargetCount(3)
38+
//Job.Clr.WithLaunchCount(1).WithWarmupCount(2).WithIterationCount(3),
39+
Job.Core.WithLaunchCount(1).WithWarmupCount(2).WithIterationCount(3)
4040
);
4141
}
4242
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
// <copyright file="EncodeJpeg.cs" company="James Jackson-South">
2-
// Copyright (c) James Jackson-South and contributors.
1+
// Copyright (c) Six Labors and contributors.
32
// Licensed under the Apache License, Version 2.0.
4-
// </copyright>
53

64
using SixLabors.ImageSharp.PixelFormats;
75

6+
using BenchmarkDotNet.Attributes;
7+
88
namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg
99
{
1010
using System.Drawing;
1111
using System.Drawing.Imaging;
1212
using System.IO;
1313

14-
using BenchmarkDotNet.Attributes;
15-
1614
using CoreImage = SixLabors.ImageSharp.Image;
1715

1816
public class EncodeJpeg : BenchmarkBase
@@ -45,19 +43,19 @@ public void Cleanup()
4543
[Benchmark(Baseline = true, Description = "System.Drawing Jpeg")]
4644
public void JpegSystemDrawing()
4745
{
48-
using (var memoryStream = new MemoryStream())
46+
using (var stream = new MemoryStream())
4947
{
50-
this.bmpDrawing.Save(memoryStream, ImageFormat.Jpeg);
48+
this.bmpDrawing.Save(stream, ImageFormat.Jpeg);
5149
}
5250
}
5351

5452
[Benchmark(Description = "ImageSharp Jpeg")]
5553
public void JpegCore()
5654
{
57-
using (var memoryStream = new MemoryStream())
55+
using (var stream = new MemoryStream())
5856
{
59-
this.bmpCore.SaveAsJpeg(memoryStream);
57+
this.bmpCore.SaveAsJpeg(stream);
6058
}
6159
}
6260
}
63-
}
61+
}

tests/ImageSharp.Benchmarks/Codecs/MultiImageBenchmarkBase.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// <copyright file="MultiImageBenchmarkBase.cs" company="James Jackson-South">
2-
// Copyright (c) James Jackson-South and contributors.
1+
// Copyright (c) Six Labors and contributors.
32
// Licensed under the Apache License, Version 2.0.
4-
// </copyright>
53

64
using BenchmarkDotNet.Configs;
75
using BenchmarkDotNet.Jobs;
@@ -18,7 +16,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs
1816
using System.Numerics;
1917

2018
using BenchmarkDotNet.Attributes;
21-
19+
using BenchmarkDotNet.Diagnosers;
2220
using SixLabors.ImageSharp.Tests;
2321

2422
using CoreImage = ImageSharp.Image;
@@ -30,15 +28,15 @@ public class Config : ManualConfig
3028
public Config()
3129
{
3230
// Uncomment if you want to use any of the diagnoser
33-
this.Add(new BenchmarkDotNet.Diagnosers.MemoryDiagnoser());
31+
this.Add(MemoryDiagnoser.Default);
3432
}
3533

3634
public class ShortClr : Benchmarks.Config
3735
{
3836
public ShortClr()
3937
{
4038
this.Add(
41-
Job.Core.WithLaunchCount(1).WithWarmupCount(1).WithTargetCount(2)
39+
Job.Core.WithLaunchCount(1).WithWarmupCount(1).WithIterationCount(2)
4240
);
4341
}
4442
}
@@ -47,7 +45,7 @@ public ShortClr()
4745
protected Dictionary<string, byte[]> FileNamesToBytes = new Dictionary<string, byte[]>();
4846

4947
protected Dictionary<string, Image<Rgba32>> FileNamesToImageSharpImages = new Dictionary<string, Image<Rgba32>>();
50-
protected Dictionary<string, System.Drawing.Bitmap> FileNamesToSystemDrawingImages = new Dictionary<string, System.Drawing.Bitmap>();
48+
protected Dictionary<string, Bitmap> FileNamesToSystemDrawingImages = new Dictionary<string, System.Drawing.Bitmap>();
5149

5250
/// <summary>
5351
/// The values of this enum separate input files into categories
@@ -152,7 +150,7 @@ protected void ForEachStream(Func<MemoryStream, object> operation)
152150
{
153151
foreach (KeyValuePair<string, byte[]> kv in this.FileNames2Bytes)
154152
{
155-
using (MemoryStream memoryStream = new MemoryStream(kv.Value))
153+
using (var memoryStream = new MemoryStream(kv.Value))
156154
{
157155
try
158156
{
@@ -179,7 +177,7 @@ protected override void ReadFilesImpl()
179177
byte[] bytes = kv.Value;
180178
string fn = kv.Key;
181179

182-
using (MemoryStream ms1 = new MemoryStream(bytes))
180+
using (var ms1 = new MemoryStream(bytes))
183181
{
184182
this.FileNamesToImageSharpImages[fn] = CoreImage.Load<Rgba32>(ms1);
185183

@@ -223,7 +221,7 @@ protected void ForEachImageSharpImage(Func<Image<Rgba32>, object> operation)
223221

224222
protected void ForEachImageSharpImage(Func<Image<Rgba32>, MemoryStream, object> operation)
225223
{
226-
using (MemoryStream workStream = new MemoryStream())
224+
using (var workStream = new MemoryStream())
227225
{
228226

229227
this.ForEachImageSharpImage(

tests/ImageSharp.Benchmarks/Color/ColorEquality.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
// <copyright file="ColorEquality.cs" company="James Jackson-South">
2-
// Copyright (c) James Jackson-South and contributors.
1+
// Copyright (c) Six Labors and contributors.
32
// Licensed under the Apache License, Version 2.0.
4-
// </copyright>
53

6-
namespace SixLabors.ImageSharp.Benchmarks
7-
{
8-
using BenchmarkDotNet.Attributes;
4+
using BenchmarkDotNet.Attributes;
95

10-
using SixLabors.ImageSharp.PixelFormats;
6+
using SixLabors.ImageSharp.PixelFormats;
117

8+
namespace SixLabors.ImageSharp.Benchmarks
9+
{
1210
using SystemColor = System.Drawing.Color;
1311

1412
public class ColorEquality

0 commit comments

Comments
 (0)