Skip to content

Commit e925b77

Browse files
Merge pull request #2886 from SixLabors/js/fix-benchmarks
Get the benchmarks working again.
2 parents 9c9cc0d + 3448ea4 commit e925b77

35 files changed

+231
-262
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: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,24 @@ private string TestImageFullPath
1919

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

2924
[Params(TestImages.Bmp.Car)]
3025
public string TestImage { get; set; }
3126

3227
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
3328
public SDSize BmpSystemDrawing()
3429
{
35-
using var memoryStream = new MemoryStream(this.bmpBytes);
36-
using var image = SDImage.FromStream(memoryStream);
30+
using MemoryStream memoryStream = new(this.bmpBytes);
31+
using SDImage image = SDImage.FromStream(memoryStream);
3732
return image.Size;
3833
}
3934

4035
[Benchmark(Description = "ImageSharp Bmp")]
4136
public Size BmpImageSharp()
4237
{
43-
using var memoryStream = new MemoryStream(this.bmpBytes);
44-
using var image = Image.Load<Rgba32>(memoryStream);
38+
using MemoryStream memoryStream = new(this.bmpBytes);
39+
using Image<Rgba32> image = Image.Load<Rgba32>(memoryStream);
4540
return new Size(image.Width, image.Height);
4641
}
4742
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs;
1212
[Config(typeof(Config.Short))]
1313
public class EncodeBmp
1414
{
15-
private Stream bmpStream;
15+
private FileStream bmpStream;
1616
private SDImage bmpDrawing;
1717
private Image<Rgba32> bmpCore;
1818

@@ -40,14 +40,14 @@ public void Cleanup()
4040
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
4141
public void BmpSystemDrawing()
4242
{
43-
using var memoryStream = new MemoryStream();
43+
using MemoryStream memoryStream = new();
4444
this.bmpDrawing.Save(memoryStream, ImageFormat.Bmp);
4545
}
4646

4747
[Benchmark(Description = "ImageSharp Bmp")]
4848
public void BmpImageSharp()
4949
{
50-
using var memoryStream = new MemoryStream();
50+
using MemoryStream memoryStream = new();
5151
this.bmpCore.SaveAsBmp(memoryStream);
5252
}
5353
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,24 @@ private string TestImageFullPath
1818
=> Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
1919

2020
[GlobalSetup]
21-
public void ReadImages()
22-
{
23-
if (this.gifBytes == null)
24-
{
25-
this.gifBytes = File.ReadAllBytes(this.TestImageFullPath);
26-
}
27-
}
21+
public void ReadImages() => this.gifBytes ??= File.ReadAllBytes(this.TestImageFullPath);
2822

2923
[Params(TestImages.Gif.Cheers)]
3024
public string TestImage { get; set; }
3125

3226
[Benchmark(Baseline = true, Description = "System.Drawing Gif")]
3327
public SDSize GifSystemDrawing()
3428
{
35-
using var memoryStream = new MemoryStream(this.gifBytes);
36-
using var image = SDImage.FromStream(memoryStream);
29+
using MemoryStream memoryStream = new(this.gifBytes);
30+
using SDImage image = SDImage.FromStream(memoryStream);
3731
return image.Size;
3832
}
3933

4034
[Benchmark(Description = "ImageSharp Gif")]
4135
public Size GifImageSharp()
4236
{
43-
using var memoryStream = new MemoryStream(this.gifBytes);
44-
using var image = Image.Load<Rgba32>(memoryStream);
37+
using MemoryStream memoryStream = new(this.gifBytes);
38+
using Image<Rgba32> image = Image.Load<Rgba32>(memoryStream);
4539
return new Size(image.Width, image.Height);
4640
}
4741
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ namespace SixLabors.ImageSharp.Benchmarks.Codecs;
1616
public class EncodeGif
1717
{
1818
// System.Drawing needs this.
19-
private Stream bmpStream;
19+
private FileStream bmpStream;
2020
private SDImage bmpDrawing;
2121
private Image<Rgba32> bmpCore;
2222

2323
// Try to get as close to System.Drawing's output as possible
24-
private readonly GifEncoder encoder = new GifEncoder
24+
private readonly GifEncoder encoder = new()
2525
{
2626
Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4 })
2727
};
@@ -53,14 +53,14 @@ public void Cleanup()
5353
[Benchmark(Baseline = true, Description = "System.Drawing Gif")]
5454
public void GifSystemDrawing()
5555
{
56-
using var memoryStream = new MemoryStream();
56+
using MemoryStream memoryStream = new();
5757
this.bmpDrawing.Save(memoryStream, ImageFormat.Gif);
5858
}
5959

6060
[Benchmark(Description = "ImageSharp Gif")]
6161
public void GifImageSharp()
6262
{
63-
using var memoryStream = new MemoryStream();
63+
using MemoryStream memoryStream = new();
6464
this.bmpCore.SaveAsGif(memoryStream, this.encoder);
6565
}
6666
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public void EncodeGifImageSharp()
2222
=> this.ForEachImageSharpImage((img, ms) =>
2323
{
2424
// Try to get as close to System.Drawing's output as possible
25-
var options = new GifEncoder
25+
GifEncoder options = new()
2626
{
2727
Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4 })
2828
};

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()

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void Setup()
3636

3737
if (ptr % 16 != 0)
3838
{
39-
throw new Exception("ptr is unaligned");
39+
throw new InvalidOperationException("ptr is unaligned");
4040
}
4141

4242
this.alignedPtr = (float*)ptr;
@@ -67,21 +67,21 @@ public void SimdUtils_FastRound_Vector8()
6767
ref Block8x8F b = ref this.block;
6868

6969
ref Vector<float> row0 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V0L);
70-
row0 = SimdUtils.FastRound(row0);
70+
row0 = row0.FastRound();
7171
ref Vector<float> row1 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V1L);
72-
row1 = SimdUtils.FastRound(row1);
72+
row1 = row1.FastRound();
7373
ref Vector<float> row2 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V2L);
74-
row2 = SimdUtils.FastRound(row2);
74+
row2 = row2.FastRound();
7575
ref Vector<float> row3 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V3L);
76-
row3 = SimdUtils.FastRound(row3);
76+
row3 = row3.FastRound();
7777
ref Vector<float> row4 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V4L);
78-
row4 = SimdUtils.FastRound(row4);
78+
row4 = row4.FastRound();
7979
ref Vector<float> row5 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V5L);
80-
row5 = SimdUtils.FastRound(row5);
80+
row5 = row5.FastRound();
8181
ref Vector<float> row6 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V6L);
82-
row6 = SimdUtils.FastRound(row6);
82+
row6 = row6.FastRound();
8383
ref Vector<float> row7 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V7L);
84-
row7 = SimdUtils.FastRound(row7);
84+
row7 = row7.FastRound();
8585
}
8686

8787
[Benchmark]
@@ -90,21 +90,21 @@ public void SimdUtils_FastRound_Vector8_ForceAligned()
9090
ref Block8x8F b = ref Unsafe.AsRef<Block8x8F>(this.alignedPtr);
9191

9292
ref Vector<float> row0 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V0L);
93-
row0 = SimdUtils.FastRound(row0);
93+
row0 = row0.FastRound();
9494
ref Vector<float> row1 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V1L);
95-
row1 = SimdUtils.FastRound(row1);
95+
row1 = row1.FastRound();
9696
ref Vector<float> row2 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V2L);
97-
row2 = SimdUtils.FastRound(row2);
97+
row2 = row2.FastRound();
9898
ref Vector<float> row3 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V3L);
99-
row3 = SimdUtils.FastRound(row3);
99+
row3 = row3.FastRound();
100100
ref Vector<float> row4 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V4L);
101-
row4 = SimdUtils.FastRound(row4);
101+
row4 = row4.FastRound();
102102
ref Vector<float> row5 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V5L);
103-
row5 = SimdUtils.FastRound(row5);
103+
row5 = row5.FastRound();
104104
ref Vector<float> row6 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V6L);
105-
row6 = SimdUtils.FastRound(row6);
105+
row6 = row6.FastRound();
106106
ref Vector<float> row7 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V7L);
107-
row7 = SimdUtils.FastRound(row7);
107+
row7 = row7.FastRound();
108108
}
109109

110110
[Benchmark]
@@ -117,20 +117,20 @@ public void SimdUtils_FastRound_Vector8_Grouped()
117117
ref Vector<float> row2 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V2L);
118118
ref Vector<float> row3 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V3L);
119119

120-
row0 = SimdUtils.FastRound(row0);
121-
row1 = SimdUtils.FastRound(row1);
122-
row2 = SimdUtils.FastRound(row2);
123-
row3 = SimdUtils.FastRound(row3);
120+
row0 = row0.FastRound();
121+
row1 = row1.FastRound();
122+
row2 = row2.FastRound();
123+
row3 = row3.FastRound();
124124

125125
row0 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V4L);
126126
row1 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V5L);
127127
row2 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V6L);
128128
row3 = ref Unsafe.As<Vector4, Vector<float>>(ref b.V7L);
129129

130-
row0 = SimdUtils.FastRound(row0);
131-
row1 = SimdUtils.FastRound(row1);
132-
row2 = SimdUtils.FastRound(row2);
133-
row3 = SimdUtils.FastRound(row3);
130+
row0 = row0.FastRound();
131+
row1 = row1.FastRound();
132+
row2 = row2.FastRound();
133+
row3 = row3.FastRound();
134134
}
135135

136136
[Benchmark]
@@ -174,7 +174,7 @@ public void Sse41_V1()
174174
}
175175

176176
[Benchmark]
177-
public unsafe void Sse41_V2()
177+
public void Sse41_V2()
178178
{
179179
ref Vector128<float> p = ref Unsafe.As<Block8x8F, Vector128<float>>(ref this.block);
180180
p = Sse41.RoundToNearestInteger(p);
@@ -214,7 +214,7 @@ public unsafe void Sse41_V2()
214214
}
215215

216216
[Benchmark]
217-
public unsafe void Sse41_V3()
217+
public void Sse41_V3()
218218
{
219219
ref Vector128<float> p = ref Unsafe.As<Block8x8F, Vector128<float>>(ref this.block);
220220
p = Sse41.RoundToNearestInteger(p);
@@ -228,7 +228,7 @@ public unsafe void Sse41_V3()
228228
}
229229

230230
[Benchmark]
231-
public unsafe void Sse41_V4()
231+
public void Sse41_V4()
232232
{
233233
ref Vector128<float> p = ref Unsafe.As<Block8x8F, Vector128<float>>(ref this.block);
234234
nuint offset = (uint)sizeof(Vector128<float>);
@@ -271,7 +271,7 @@ public unsafe void Sse41_V4()
271271
}
272272

273273
[Benchmark]
274-
public unsafe void Sse41_V5_Unaligned()
274+
public void Sse41_V5_Unaligned()
275275
{
276276
float* p = this.alignedPtr + 1;
277277

@@ -356,7 +356,7 @@ public unsafe void Sse41_V5_Unaligned()
356356
}
357357

358358
[Benchmark]
359-
public unsafe void Sse41_V5_Aligned()
359+
public void Sse41_V5_Aligned()
360360
{
361361
float* p = this.alignedPtr;
362362

0 commit comments

Comments
 (0)