From 93f8bdf94f5d4c7d525a1721bb34cddb4c8cdfe4 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 2 Apr 2025 22:42:47 +1000 Subject: [PATCH] ImageMagick.NET to GIF encoder benchmark --- .../Codecs/Gif/EncodeGif.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs b/tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs index 2b2428210..b8f8f7851 100644 --- a/tests/ImageSharp.Benchmarks/Codecs/Gif/EncodeGif.cs +++ b/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 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(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