Skip to content

Commit 9be7d84

Browse files
Get the benchmarks working again.
1 parent 9c9cc0d commit 9be7d84

36 files changed

+262
-248
lines changed

tests/ImageSharp.Benchmarks/Bulk/FromRgba32Bytes.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ public void OptimizedBulk()
6262
=> PixelOperations<TPixel>.Instance.FromRgba32Bytes(this.configuration, this.source.GetSpan(), this.destination.GetSpan(), this.Count);
6363
}
6464

65-
public class FromRgba32Bytes_ToRgba32 : FromRgba32Bytes<Rgba32>
66-
{
67-
}
65+
public class FromRgba32Bytes_ToRgba32 : FromRgba32Bytes<Rgba32>;
6866

6967
public class FromRgba32Bytes_ToBgra32 : FromRgba32Bytes<Bgra32>
7068
{

tests/ImageSharp.Benchmarks/Bulk/Vector4Factory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ private static Vector4[] GenerateRandomVectorArray(Random rnd, int length, float
3030
}
3131

3232
private static float GetRandomFloat(Random rnd, float minVal, float maxVal)
33-
=> (float)rnd.NextDouble() * (maxVal - minVal) + minVal;
33+
=> ((float)rnd.NextDouble() * (maxVal - minVal)) + minVal;
3434
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
#if OS_WINDOWS
45
using BenchmarkDotNet.Attributes;
56
using SixLabors.ImageSharp.PixelFormats;
67
using SixLabors.ImageSharp.Tests;
@@ -19,29 +20,25 @@ private string TestImageFullPath
1920

2021
[GlobalSetup]
2122
public void ReadImages()
22-
{
23-
if (this.bmpBytes == null)
24-
{
25-
this.bmpBytes = File.ReadAllBytes(this.TestImageFullPath);
26-
}
27-
}
23+
=> this.bmpBytes ??= File.ReadAllBytes(this.TestImageFullPath);
2824

2925
[Params(TestImages.Bmp.Car)]
3026
public string TestImage { get; set; }
3127

3228
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
3329
public SDSize BmpSystemDrawing()
3430
{
35-
using var memoryStream = new MemoryStream(this.bmpBytes);
36-
using var image = SDImage.FromStream(memoryStream);
31+
using MemoryStream memoryStream = new(this.bmpBytes);
32+
using SDImage image = SDImage.FromStream(memoryStream);
3733
return image.Size;
3834
}
3935

4036
[Benchmark(Description = "ImageSharp Bmp")]
4137
public Size BmpImageSharp()
4238
{
43-
using var memoryStream = new MemoryStream(this.bmpBytes);
44-
using var image = Image.Load<Rgba32>(memoryStream);
39+
using MemoryStream memoryStream = new(this.bmpBytes);
40+
using Image<Rgba32> image = Image.Load<Rgba32>(memoryStream);
4541
return new Size(image.Width, image.Height);
4642
}
4743
}
44+
#endif

tests/ImageSharp.Benchmarks/Codecs/Bmp/EncodeBmp.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
#if OS_WINDOWS
45
using System.Drawing.Imaging;
56
using BenchmarkDotNet.Attributes;
67
using SixLabors.ImageSharp.PixelFormats;
@@ -12,7 +13,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs;
1213
[Config(typeof(Config.Short))]
1314
public class EncodeBmp
1415
{
15-
private Stream bmpStream;
16+
private FileStream bmpStream;
1617
private SDImage bmpDrawing;
1718
private Image<Rgba32> bmpCore;
1819

@@ -40,14 +41,15 @@ public void Cleanup()
4041
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
4142
public void BmpSystemDrawing()
4243
{
43-
using var memoryStream = new MemoryStream();
44+
using MemoryStream memoryStream = new();
4445
this.bmpDrawing.Save(memoryStream, ImageFormat.Bmp);
4546
}
4647

4748
[Benchmark(Description = "ImageSharp Bmp")]
4849
public void BmpImageSharp()
4950
{
50-
using var memoryStream = new MemoryStream();
51+
using MemoryStream memoryStream = new();
5152
this.bmpCore.SaveAsBmp(memoryStream);
5253
}
5354
}
55+
#endif

tests/ImageSharp.Benchmarks/Codecs/Bmp/EncodeBmpMultiple.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
#if OS_WINDOWS
45
using System.Drawing.Imaging;
56
using BenchmarkDotNet.Attributes;
67
using SixLabors.ImageSharp.Formats.Bmp;
@@ -28,3 +29,4 @@ public void EncodeBmpSystemDrawing()
2829
return null;
2930
});
3031
}
32+
#endif

tests/ImageSharp.Benchmarks/Codecs/Gif/DecodeGif.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
#if OS_WINDOWS
45
using BenchmarkDotNet.Attributes;
56
using SixLabors.ImageSharp.PixelFormats;
67
using SixLabors.ImageSharp.Tests;
@@ -26,22 +27,23 @@ public void ReadImages()
2627
}
2728
}
2829

29-
[Params(TestImages.Gif.Cheers)]
30+
[Params(TestImages.Gif.Rings)]
3031
public string TestImage { get; set; }
3132

3233
[Benchmark(Baseline = true, Description = "System.Drawing Gif")]
3334
public SDSize GifSystemDrawing()
3435
{
35-
using var memoryStream = new MemoryStream(this.gifBytes);
36-
using var image = SDImage.FromStream(memoryStream);
36+
using MemoryStream memoryStream = new(this.gifBytes);
37+
using SDImage image = SDImage.FromStream(memoryStream);
3738
return image.Size;
3839
}
3940

4041
[Benchmark(Description = "ImageSharp Gif")]
4142
public Size GifImageSharp()
4243
{
43-
using var memoryStream = new MemoryStream(this.gifBytes);
44-
using var image = Image.Load<Rgba32>(memoryStream);
44+
using MemoryStream memoryStream = new(this.gifBytes);
45+
using Image<Rgba32> image = Image.Load<Rgba32>(memoryStream);
4546
return new Size(image.Width, image.Height);
4647
}
4748
}
49+
#endif

tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
#if OS_WINDOWS
45
using System.Drawing.Imaging;
56
using BenchmarkDotNet.Attributes;
67
using SixLabors.ImageSharp.Formats.Gif;
@@ -16,12 +17,12 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs;
1617
public class EncodeGif
1718
{
1819
// System.Drawing needs this.
19-
private Stream bmpStream;
20+
private FileStream bmpStream;
2021
private SDImage bmpDrawing;
2122
private Image<Rgba32> bmpCore;
2223

2324
// Try to get as close to System.Drawing's output as possible
24-
private readonly GifEncoder encoder = new GifEncoder
25+
private readonly GifEncoder encoder = new()
2526
{
2627
Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4 })
2728
};
@@ -53,14 +54,15 @@ public void Cleanup()
5354
[Benchmark(Baseline = true, Description = "System.Drawing Gif")]
5455
public void GifSystemDrawing()
5556
{
56-
using var memoryStream = new MemoryStream();
57+
using MemoryStream memoryStream = new();
5758
this.bmpDrawing.Save(memoryStream, ImageFormat.Gif);
5859
}
5960

6061
[Benchmark(Description = "ImageSharp Gif")]
6162
public void GifImageSharp()
6263
{
63-
using var memoryStream = new MemoryStream();
64+
using MemoryStream memoryStream = new();
6465
this.bmpCore.SaveAsGif(memoryStream, this.encoder);
6566
}
6667
}
68+
#endif

tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGifMultiple.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
33

4+
#if OS_WINDOWS
45
using System.Drawing.Imaging;
56
using BenchmarkDotNet.Attributes;
67
using SixLabors.ImageSharp.Formats.Gif;
@@ -22,7 +23,7 @@ public void EncodeGifImageSharp()
2223
=> this.ForEachImageSharpImage((img, ms) =>
2324
{
2425
// Try to get as close to System.Drawing's output as possible
25-
var options = new GifEncoder
26+
GifEncoder options = new()
2627
{
2728
Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4 })
2829
};
@@ -39,3 +40,4 @@ public void EncodeGifSystemDrawing()
3940
return null;
4041
});
4142
}
43+
#endif

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg.BlockOperations;
1212
public class Block8x8F_LoadFromInt16
1313
{
1414
private Block8x8 source;
15-
16-
private Block8x8F dest = default;
15+
private Block8x8F destination;
1716

1817
[GlobalSetup]
1918
public void Setup()
@@ -30,16 +29,10 @@ public void Setup()
3029
}
3130

3231
[Benchmark(Baseline = true)]
33-
public void Scalar()
34-
{
35-
this.dest.LoadFromInt16Scalar(ref this.source);
36-
}
32+
public void Scalar() => this.destination.LoadFromInt16Scalar(ref this.source);
3733

3834
[Benchmark]
39-
public void ExtendedAvx2()
40-
{
41-
this.dest.LoadFromInt16ExtendedAvx2(ref this.source);
42-
}
35+
public void ExtendedAvx2() => this.destination.LoadFromInt16ExtendedAvx2(ref this.source);
4336

4437
// RESULT:
4538
// Method | Mean | Error | StdDev | Scaled |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class Block8x8F_Quantize
1111
{
1212
private Block8x8F block = CreateFromScalar(1);
1313
private Block8x8F quant = CreateFromScalar(1);
14-
private Block8x8 result = default;
14+
private Block8x8 result;
1515

1616
[Benchmark]
1717
public short Quantize()

0 commit comments

Comments
 (0)