Skip to content

Commit

Permalink
Update missed test and benchmarks project
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Sep 15, 2022
1 parent d14c820 commit 5528a29
Show file tree
Hide file tree
Showing 125 changed files with 8,147 additions and 8,364 deletions.
58 changes: 28 additions & 30 deletions tests/ImageSharp.Benchmarks/Codecs/Bmp/DecodeBmp.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;
using SDImage = System.Drawing.Image;
using SDSize = System.Drawing.Size;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
namespace SixLabors.ImageSharp.Benchmarks.Codecs;

[Config(typeof(Config.ShortMultiFramework))]
public class DecodeBmp
{
[Config(typeof(Config.ShortMultiFramework))]
public class DecodeBmp
{
private byte[] bmpBytes;
private byte[] bmpBytes;

private string TestImageFullPath
=> Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
private string TestImageFullPath
=> Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);

[GlobalSetup]
public void ReadImages()
[GlobalSetup]
public void ReadImages()
{
if (this.bmpBytes == null)
{
if (this.bmpBytes == null)
{
this.bmpBytes = File.ReadAllBytes(this.TestImageFullPath);
}
this.bmpBytes = File.ReadAllBytes(this.TestImageFullPath);
}
}

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

[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
public SDSize BmpSystemDrawing()
{
using var memoryStream = new MemoryStream(this.bmpBytes);
using var image = SDImage.FromStream(memoryStream);
return image.Size;
}
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
public SDSize BmpSystemDrawing()
{
using var memoryStream = new MemoryStream(this.bmpBytes);
using var image = SDImage.FromStream(memoryStream);
return image.Size;
}

[Benchmark(Description = "ImageSharp Bmp")]
public Size BmpImageSharp()
{
using var memoryStream = new MemoryStream(this.bmpBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return new Size(image.Width, image.Height);
}
[Benchmark(Description = "ImageSharp Bmp")]
public Size BmpImageSharp()
{
using var memoryStream = new MemoryStream(this.bmpBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return new Size(image.Width, image.Height);
}
}
72 changes: 35 additions & 37 deletions tests/ImageSharp.Benchmarks/Codecs/Bmp/EncodeBmp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,52 @@
// Licensed under the Six Labors Split License.

using System.Drawing.Imaging;
using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;
using SDImage = System.Drawing.Image;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
namespace SixLabors.ImageSharp.Benchmarks.Codecs;

[Config(typeof(Config.ShortMultiFramework))]
public class EncodeBmp
{
[Config(typeof(Config.ShortMultiFramework))]
public class EncodeBmp
{
private Stream bmpStream;
private SDImage bmpDrawing;
private Image<Rgba32> bmpCore;
private Stream bmpStream;
private SDImage bmpDrawing;
private Image<Rgba32> bmpCore;

[GlobalSetup]
public void ReadImages()
[GlobalSetup]
public void ReadImages()
{
if (this.bmpStream == null)
{
if (this.bmpStream == null)
{
this.bmpStream = File.OpenRead(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImages.Bmp.Car));
this.bmpCore = Image.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.bmpDrawing = SDImage.FromStream(this.bmpStream);
}
this.bmpStream = File.OpenRead(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImages.Bmp.Car));
this.bmpCore = Image.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.bmpDrawing = SDImage.FromStream(this.bmpStream);
}
}

[GlobalCleanup]
public void Cleanup()
{
this.bmpStream.Dispose();
this.bmpStream = null;
this.bmpCore.Dispose();
this.bmpDrawing.Dispose();
}
[GlobalCleanup]
public void Cleanup()
{
this.bmpStream.Dispose();
this.bmpStream = null;
this.bmpCore.Dispose();
this.bmpDrawing.Dispose();
}

[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
public void BmpSystemDrawing()
{
using var memoryStream = new MemoryStream();
this.bmpDrawing.Save(memoryStream, ImageFormat.Bmp);
}
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")]
public void BmpSystemDrawing()
{
using var memoryStream = new MemoryStream();
this.bmpDrawing.Save(memoryStream, ImageFormat.Bmp);
}

[Benchmark(Description = "ImageSharp Bmp")]
public void BmpImageSharp()
{
using var memoryStream = new MemoryStream();
this.bmpCore.SaveAsBmp(memoryStream);
}
[Benchmark(Description = "ImageSharp Bmp")]
public void BmpImageSharp()
{
using var memoryStream = new MemoryStream();
this.bmpCore.SaveAsBmp(memoryStream);
}
}
40 changes: 19 additions & 21 deletions tests/ImageSharp.Benchmarks/Codecs/Bmp/EncodeBmpMultiple.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.Collections.Generic;
using System.Drawing.Imaging;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Formats.Bmp;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
namespace SixLabors.ImageSharp.Benchmarks.Codecs;

[Config(typeof(Config.ShortMultiFramework))]
public class EncodeBmpMultiple : MultiImageBenchmarkBase.WithImagesPreloaded
{
[Config(typeof(Config.ShortMultiFramework))]
public class EncodeBmpMultiple : MultiImageBenchmarkBase.WithImagesPreloaded
{
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Bmp/", "Jpg/baseline" };
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Bmp/", "Jpg/baseline" };

[Benchmark(Description = "EncodeBmpMultiple - ImageSharp")]
public void EncodeBmpImageSharp()
=> this.ForEachImageSharpImage((img, ms) =>
{
img.Save(ms, new BmpEncoder());
return null;
});
[Benchmark(Description = "EncodeBmpMultiple - ImageSharp")]
public void EncodeBmpImageSharp()
=> this.ForEachImageSharpImage((img, ms) =>
{
img.Save(ms, new BmpEncoder());
return null;
});

[Benchmark(Baseline = true, Description = "EncodeBmpMultiple - System.Drawing")]
public void EncodeBmpSystemDrawing()
=> this.ForEachSystemDrawingImage((img, ms) =>
{
img.Save(ms, ImageFormat.Bmp);
return null;
});
}
[Benchmark(Baseline = true, Description = "EncodeBmpMultiple - System.Drawing")]
public void EncodeBmpSystemDrawing()
=> this.ForEachSystemDrawingImage((img, ms) =>
{
img.Save(ms, ImageFormat.Bmp);
return null;
});
}
58 changes: 28 additions & 30 deletions tests/ImageSharp.Benchmarks/Codecs/Gif/DecodeGif.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;
using SDImage = System.Drawing.Image;
using SDSize = System.Drawing.Size;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
namespace SixLabors.ImageSharp.Benchmarks.Codecs;

[Config(typeof(Config.ShortMultiFramework))]
public class DecodeGif
{
[Config(typeof(Config.ShortMultiFramework))]
public class DecodeGif
{
private byte[] gifBytes;
private byte[] gifBytes;

private string TestImageFullPath
=> Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
private string TestImageFullPath
=> Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);

[GlobalSetup]
public void ReadImages()
[GlobalSetup]
public void ReadImages()
{
if (this.gifBytes == null)
{
if (this.gifBytes == null)
{
this.gifBytes = File.ReadAllBytes(this.TestImageFullPath);
}
this.gifBytes = File.ReadAllBytes(this.TestImageFullPath);
}
}

[Params(TestImages.Gif.Rings)]
public string TestImage { get; set; }
[Params(TestImages.Gif.Rings)]
public string TestImage { get; set; }

[Benchmark(Baseline = true, Description = "System.Drawing Gif")]
public SDSize GifSystemDrawing()
{
using var memoryStream = new MemoryStream(this.gifBytes);
using var image = SDImage.FromStream(memoryStream);
return image.Size;
}
[Benchmark(Baseline = true, Description = "System.Drawing Gif")]
public SDSize GifSystemDrawing()
{
using var memoryStream = new MemoryStream(this.gifBytes);
using var image = SDImage.FromStream(memoryStream);
return image.Size;
}

[Benchmark(Description = "ImageSharp Gif")]
public Size GifImageSharp()
{
using var memoryStream = new MemoryStream(this.gifBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return new Size(image.Width, image.Height);
}
[Benchmark(Description = "ImageSharp Gif")]
public Size GifImageSharp()
{
using var memoryStream = new MemoryStream(this.gifBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return new Size(image.Width, image.Height);
}
}
Loading

0 comments on commit 5528a29

Please sign in to comment.