Browse Source

ImageMagick.NET to GIF encoder benchmark

pull/2894/head
James Jackson-South 10 months ago
parent
commit
93f8bdf94f
  1. 16
      tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs

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

@ -3,6 +3,7 @@
using System.Drawing.Imaging;
using BenchmarkDotNet.Attributes;
using ImageMagick;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
@ -18,6 +19,7 @@ public abstract class EncodeGif
private FileStream bmpStream;
private SDImage bmpDrawing;
private Image<Rgba32> bmpCore;
private MagickImageCollection magickImage;
protected abstract GifEncoder Encoder { get; }
@ -29,10 +31,14 @@ public abstract class EncodeGif
{
if (this.bmpStream == null)
{
this.bmpStream = File.OpenRead(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage));
string filePath = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
this.bmpStream = File.OpenRead(filePath);
this.bmpCore = Image.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.bmpDrawing = SDImage.FromStream(this.bmpStream);
this.bmpStream.Position = 0;
this.magickImage = new MagickImageCollection(this.bmpStream);
}
}
@ -43,6 +49,7 @@ public abstract class EncodeGif
this.bmpStream = null;
this.bmpCore.Dispose();
this.bmpDrawing.Dispose();
this.magickImage.Dispose();
}
[Benchmark(Baseline = true, Description = "System.Drawing Gif")]
@ -58,6 +65,13 @@ public abstract class EncodeGif
using MemoryStream memoryStream = new();
this.bmpCore.SaveAsGif(memoryStream, this.Encoder);
}
[Benchmark(Description = "Magick.NET Gif")]
public void GifMagickNet()
{
using MemoryStream ms = new();
this.magickImage.Write(ms, MagickFormat.Gif);
}
}
public class EncodeGif_DefaultEncoder : EncodeGif

Loading…
Cancel
Save