mirror of https://github.com/SixLabors/ImageSharp
committed by
GitHub
38 changed files with 518 additions and 634 deletions
@ -0,0 +1,57 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Drawing; |
||||
|
using System.IO; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Tests; |
||||
|
using CoreSize = SixLabors.Primitives.Size; |
||||
|
using SDImage = System.Drawing.Image; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] |
||||
|
public class DecodeBmp : BenchmarkBase |
||||
|
{ |
||||
|
private byte[] bmpBytes; |
||||
|
|
||||
|
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); |
||||
|
|
||||
|
[GlobalSetup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.bmpBytes == null) |
||||
|
{ |
||||
|
this.bmpBytes = File.ReadAllBytes(this.TestImageFullPath); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Params(TestImages.Bmp.Car)] |
||||
|
public string TestImage { get; set; } |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")] |
||||
|
public Size BmpSystemDrawing() |
||||
|
{ |
||||
|
using (var memoryStream = new MemoryStream(this.bmpBytes)) |
||||
|
{ |
||||
|
using (var image = SDImage.FromStream(memoryStream)) |
||||
|
{ |
||||
|
return image.Size; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Bmp")] |
||||
|
public CoreSize BmpCore() |
||||
|
{ |
||||
|
using (var memoryStream = new MemoryStream(this.bmpBytes)) |
||||
|
{ |
||||
|
using (var image = Image.Load<Rgba32>(memoryStream)) |
||||
|
{ |
||||
|
return new CoreSize(image.Width, image.Height); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,75 @@ |
|||||
|
// <copyright file="DecodePng.cs" company="James Jackson-South">
|
||||
|
// Copyright (c) James Jackson-South and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
// </copyright>
|
||||
|
|
||||
|
using System.IO; |
||||
|
using System.Runtime.CompilerServices; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Tests; |
||||
|
using CoreSize = SixLabors.Primitives.Size; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] |
||||
|
public class DecodeFilteredPng : BenchmarkBase |
||||
|
{ |
||||
|
private byte[] filter0; |
||||
|
private byte[] filter1; |
||||
|
private byte[] filter2; |
||||
|
private byte[] filter3; |
||||
|
private byte[] filter4; |
||||
|
|
||||
|
[GlobalSetup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
this.filter0 = File.ReadAllBytes(TestImageFullPath(TestImages.Png.Filter0)); |
||||
|
this.filter1 = File.ReadAllBytes(TestImageFullPath(TestImages.Png.Filter1)); |
||||
|
this.filter2 = File.ReadAllBytes(TestImageFullPath(TestImages.Png.Filter2)); |
||||
|
this.filter3 = File.ReadAllBytes(TestImageFullPath(TestImages.Png.Filter3)); |
||||
|
this.filter4 = File.ReadAllBytes(TestImageFullPath(TestImages.Png.Filter4)); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "None-filtered PNG file")] |
||||
|
public CoreSize PngFilter0() |
||||
|
{ |
||||
|
return LoadPng(this.filter0); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "Sub-filtered PNG file")] |
||||
|
public CoreSize PngFilter1() |
||||
|
{ |
||||
|
return LoadPng(this.filter1); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "Up-filtered PNG file")] |
||||
|
public CoreSize PngFilter2() |
||||
|
{ |
||||
|
return LoadPng(this.filter2); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "Average-filtered PNG file")] |
||||
|
public CoreSize PngFilter3() |
||||
|
{ |
||||
|
return LoadPng(this.filter3); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "Paeth-filtered PNG file")] |
||||
|
public CoreSize PngFilter4() |
||||
|
{ |
||||
|
return LoadPng(this.filter4); |
||||
|
} |
||||
|
|
||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
||||
|
private static CoreSize LoadPng(byte[] bytes) |
||||
|
{ |
||||
|
using (var image = Image.Load<Rgba32>(bytes)) |
||||
|
{ |
||||
|
return image.Size(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static string TestImageFullPath(string path) => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, path); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Drawing; |
||||
|
using System.IO; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Tests; |
||||
|
using CoreSize = SixLabors.Primitives.Size; |
||||
|
using SDImage = System.Drawing.Image; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] |
||||
|
public class DecodeGif : BenchmarkBase |
||||
|
{ |
||||
|
private byte[] gifBytes; |
||||
|
|
||||
|
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage); |
||||
|
|
||||
|
[GlobalSetup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.gifBytes == null) |
||||
|
{ |
||||
|
this.gifBytes = File.ReadAllBytes(this.TestImageFullPath); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Params(TestImages.Gif.Rings)] |
||||
|
public string TestImage { get; set; } |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Gif")] |
||||
|
public Size GifSystemDrawing() |
||||
|
{ |
||||
|
using (var memoryStream = new MemoryStream(this.gifBytes)) |
||||
|
{ |
||||
|
using (var image = SDImage.FromStream(memoryStream)) |
||||
|
{ |
||||
|
return image.Size; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Gif")] |
||||
|
public CoreSize GifCore() |
||||
|
{ |
||||
|
using (var memoryStream = new MemoryStream(this.gifBytes)) |
||||
|
{ |
||||
|
using (var image = Image.Load<Rgba32>(memoryStream)) |
||||
|
{ |
||||
|
return new CoreSize(image.Width, image.Height); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Drawing.Imaging; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.Formats.Bmp; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] |
||||
|
public class EncodeBmpMultiple : MultiImageBenchmarkBase.WithImagesPreloaded |
||||
|
{ |
||||
|
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(Baseline = true, Description = "EncodeBmpMultiple - System.Drawing")] |
||||
|
public void EncodeBmpSystemDrawing() |
||||
|
{ |
||||
|
this.ForEachSystemDrawingImage((img, ms) => { img.Save(ms, ImageFormat.Bmp); return null; }); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Drawing.Imaging; |
||||
|
using System.IO; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.Formats.Gif; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
using SixLabors.ImageSharp.Processing.Quantization; |
||||
|
using SixLabors.ImageSharp.Tests; |
||||
|
using SDImage = System.Drawing.Image; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] |
||||
|
public class EncodeGif : BenchmarkBase |
||||
|
{ |
||||
|
// System.Drawing needs this.
|
||||
|
private Stream bmpStream; |
||||
|
private SDImage bmpDrawing; |
||||
|
private Image<Rgba32> bmpCore; |
||||
|
|
||||
|
[GlobalSetup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
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); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[GlobalCleanup] |
||||
|
public void Cleanup() |
||||
|
{ |
||||
|
this.bmpStream.Dispose(); |
||||
|
this.bmpCore.Dispose(); |
||||
|
this.bmpDrawing.Dispose(); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Gif")] |
||||
|
public void GifSystemDrawing() |
||||
|
{ |
||||
|
using (var memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpDrawing.Save(memoryStream, ImageFormat.Gif); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Gif")] |
||||
|
public void GifCore() |
||||
|
{ |
||||
|
// Try to get as close to System.Drawing's output as possible
|
||||
|
var options = new GifEncoder { Quantizer = new PaletteQuantizer(false) }; |
||||
|
using (var memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpCore.SaveAsGif(memoryStream, options); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Drawing.Imaging; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.Formats.Gif; |
||||
|
using SixLabors.ImageSharp.Processing.Quantization; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] |
||||
|
public class EncodeGifMultiple : MultiImageBenchmarkBase.WithImagesPreloaded |
||||
|
{ |
||||
|
[Params(InputImageCategory.AllImages)] |
||||
|
public override InputImageCategory InputCategory { get; set; } |
||||
|
|
||||
|
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Gif/" }; |
||||
|
|
||||
|
[Benchmark(Description = "EncodeGifMultiple - ImageSharp")] |
||||
|
public void EncodeGifImageSharp() |
||||
|
{ |
||||
|
this.ForEachImageSharpImage((img, ms) => |
||||
|
{ |
||||
|
// Try to get as close to System.Drawing's output as possible
|
||||
|
var options = new GifEncoder { Quantizer = new PaletteQuantizer(false) }; |
||||
|
img.Save(ms, options); return null; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "EncodeGifMultiple - System.Drawing")] |
||||
|
public void EncodeGifSystemDrawing() |
||||
|
{ |
||||
|
this.ForEachSystemDrawingImage((img, ms) => { img.Save(ms, ImageFormat.Gif); return null; }); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,63 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
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 |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] |
||||
|
public class EncodePng : BenchmarkBase |
||||
|
{ |
||||
|
// System.Drawing needs this.
|
||||
|
private Stream bmpStream; |
||||
|
private SDImage bmpDrawing; |
||||
|
private Image<Rgba32> bmpCore; |
||||
|
|
||||
|
[Params(false)] |
||||
|
public bool LargeImage { get; set; } |
||||
|
|
||||
|
[GlobalSetup] |
||||
|
public void ReadImages() |
||||
|
{ |
||||
|
if (this.bmpStream == null) |
||||
|
{ |
||||
|
string path = Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.LargeImage ? TestImages.Jpeg.Baseline.Jpeg420Exif : TestImages.Bmp.Car); |
||||
|
this.bmpStream = File.OpenRead(path); |
||||
|
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.bmpCore.Dispose(); |
||||
|
this.bmpDrawing.Dispose(); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing Png")] |
||||
|
public void PngSystemDrawing() |
||||
|
{ |
||||
|
using (var memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpDrawing.Save(memoryStream, ImageFormat.Png); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp Png")] |
||||
|
public void PngCore() |
||||
|
{ |
||||
|
using (var memoryStream = new MemoryStream()) |
||||
|
{ |
||||
|
this.bmpCore.SaveAsPng(memoryStream); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Drawing; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs |
||||
|
{ |
||||
|
public class GetSetPixel : BenchmarkBase |
||||
|
{ |
||||
|
[Benchmark(Baseline = true, Description = "System.Drawing GetSet pixel")] |
||||
|
public Color ResizeSystemDrawing() |
||||
|
{ |
||||
|
using (var source = new Bitmap(400, 400)) |
||||
|
{ |
||||
|
source.SetPixel(200, 200, Color.White); |
||||
|
return source.GetPixel(200, 200); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Description = "ImageSharp GetSet pixel")] |
||||
|
public Rgba32 ResizeCore() |
||||
|
{ |
||||
|
using (var image = new Image<Rgba32>(400, 400)) |
||||
|
{ |
||||
|
image[200, 200] = Rgba32.White; |
||||
|
return image[200, 200]; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
// Copyright (c) Six Labors and contributors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using System.Drawing.Imaging; |
||||
|
using BenchmarkDotNet.Attributes; |
||||
|
using SixLabors.ImageSharp.Formats.Jpeg; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg |
||||
|
{ |
||||
|
[Config(typeof(Config.ShortClr))] // It's long enough to iterate through multiple files
|
||||
|
public class EncodeJpegMultiple : MultiImageBenchmarkBase.WithImagesPreloaded |
||||
|
{ |
||||
|
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Bmp/", "Jpg/baseline" }; |
||||
|
|
||||
|
protected override IEnumerable<string> SearchPatterns => new[] { "*.bmp", "*.jpg" }; |
||||
|
|
||||
|
[Benchmark(Description = "EncodeJpegMultiple - ImageSharp")] |
||||
|
public void EncodeJpegImageSharp() |
||||
|
{ |
||||
|
this.ForEachImageSharpImage((img, ms) => { img.Save(ms, new JpegEncoder()); return null; }); |
||||
|
} |
||||
|
|
||||
|
[Benchmark(Baseline = true, Description = "EncodeJpegMultiple - System.Drawing")] |
||||
|
public void EncodeJpegSystemDrawing() |
||||
|
{ |
||||
|
this.ForEachSystemDrawingImage((img, ms) => { img.Save(ms, ImageFormat.Jpeg); return null; }); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,4 +1,4 @@ |
|||||
namespace SixLabors.ImageSharp.Benchmarks.Image.Jpeg |
namespace SixLabors.ImageSharp.Benchmarks.Codecs.Jpeg |
||||
{ |
{ |
||||
using System; |
using System; |
||||
using System.Numerics; |
using System.Numerics; |
||||
@ -1,56 +0,0 @@ |
|||||
// <copyright file="DecodeBmp.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Drawing; |
|
||||
using System.IO; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
|
|
||||
using CoreImage = ImageSharp.Image; |
|
||||
|
|
||||
using CoreSize = SixLabors.Primitives.Size; |
|
||||
|
|
||||
public class DecodeBmp : BenchmarkBase |
|
||||
{ |
|
||||
private byte[] bmpBytes; |
|
||||
|
|
||||
[GlobalSetup] |
|
||||
public void ReadImages() |
|
||||
{ |
|
||||
if (this.bmpBytes == null) |
|
||||
{ |
|
||||
this.bmpBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Baseline = true, Description = "System.Drawing Bmp")] |
|
||||
public Size BmpSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(this.bmpBytes)) |
|
||||
{ |
|
||||
using (Image image = Image.FromStream(memoryStream)) |
|
||||
{ |
|
||||
return image.Size; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Bmp")] |
|
||||
public CoreSize BmpCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(this.bmpBytes)) |
|
||||
{ |
|
||||
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(memoryStream)) |
|
||||
{ |
|
||||
return new CoreSize(image.Width, image.Height); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,74 +0,0 @@ |
|||||
// <copyright file="DecodePng.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.IO; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
|
|
||||
using SixLabors.ImageSharp; |
|
||||
using SixLabors.Primitives; |
|
||||
using CoreImage = ImageSharp.Image; |
|
||||
|
|
||||
public class DecodeFilteredPng : BenchmarkBase |
|
||||
{ |
|
||||
private MemoryStream filter0; |
|
||||
private MemoryStream filter1; |
|
||||
private MemoryStream filter2; |
|
||||
private MemoryStream filter3; |
|
||||
private MemoryStream filter4; |
|
||||
|
|
||||
[GlobalSetup] |
|
||||
public void ReadImages() |
|
||||
{ |
|
||||
this.filter0 = new MemoryStream(File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Png/filter0.png")); |
|
||||
this.filter1 = new MemoryStream(File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Png/filter1.png")); |
|
||||
this.filter2 = new MemoryStream(File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Png/filter2.png")); |
|
||||
this.filter3 = new MemoryStream(File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Png/filter3.png")); |
|
||||
this.filter4 = new MemoryStream(File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Png/filter4.png")); |
|
||||
} |
|
||||
|
|
||||
private SixLabors.Primitives.Size LoadPng(MemoryStream stream) |
|
||||
{ |
|
||||
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(stream)) |
|
||||
{ |
|
||||
return new SixLabors.Primitives.Size(image.Width, image.Height); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Baseline = true, Description = "None-filtered PNG file")] |
|
||||
public Size PngFilter0() |
|
||||
{ |
|
||||
return LoadPng(filter0); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "Sub-filtered PNG file")] |
|
||||
public Size PngFilter1() |
|
||||
{ |
|
||||
return LoadPng(filter1); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "Up-filtered PNG file")] |
|
||||
public Size PngFilter2() |
|
||||
{ |
|
||||
return LoadPng(filter2); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "Average-filtered PNG file")] |
|
||||
public Size PngFilter3() |
|
||||
{ |
|
||||
return LoadPng(filter3); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "Paeth-filtered PNG file")] |
|
||||
public Size PngFilter4() |
|
||||
{ |
|
||||
return LoadPng(filter4); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,56 +0,0 @@ |
|||||
// <copyright file="DecodeGif.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Drawing; |
|
||||
using System.IO; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
|
|
||||
using CoreImage = ImageSharp.Image; |
|
||||
|
|
||||
using CoreSize = SixLabors.Primitives.Size; |
|
||||
|
|
||||
public class DecodeGif : BenchmarkBase |
|
||||
{ |
|
||||
private byte[] gifBytes; |
|
||||
|
|
||||
[GlobalSetup] |
|
||||
public void ReadImages() |
|
||||
{ |
|
||||
if (this.gifBytes == null) |
|
||||
{ |
|
||||
this.gifBytes = File.ReadAllBytes("../ImageSharp.Tests/TestImages/Formats/Gif/rings.gif"); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Baseline = true, Description = "System.Drawing Gif")] |
|
||||
public Size GifSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(this.gifBytes)) |
|
||||
{ |
|
||||
using (Image image = Image.FromStream(memoryStream)) |
|
||||
{ |
|
||||
return image.Size; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Gif")] |
|
||||
public CoreSize GifCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream(this.gifBytes)) |
|
||||
{ |
|
||||
using (Image<Rgba32> image = CoreImage.Load<Rgba32>(memoryStream)) |
|
||||
{ |
|
||||
return new CoreSize(image.Width, image.Height); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,43 +0,0 @@ |
|||||
// <copyright file="EncodeBmpMultiple.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Collections.Generic; |
|
||||
using System.Drawing.Imaging; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
|
|
||||
using SixLabors.ImageSharp.Formats; |
|
||||
using SixLabors.ImageSharp.Formats.Bmp; |
|
||||
|
|
||||
[Config(typeof(Config.ShortClr))] |
|
||||
public class EncodeBmpMultiple : MultiImageBenchmarkBase.WithImagesPreloaded |
|
||||
{ |
|
||||
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(Baseline = true, Description = "EncodeBmpMultiple - System.Drawing")] |
|
||||
public void EncodeBmpSystemDrawing() |
|
||||
{ |
|
||||
this.ForEachSystemDrawingImage( |
|
||||
(img, ms) => |
|
||||
{ |
|
||||
img.Save(ms, ImageFormat.Bmp); |
|
||||
return null; |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,63 +0,0 @@ |
|||||
// <copyright file="EncodeGif.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Drawing; |
|
||||
using System.Drawing.Imaging; |
|
||||
using System.IO; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
|
|
||||
using CoreImage = ImageSharp.Image; |
|
||||
|
|
||||
public class EncodeGif : BenchmarkBase |
|
||||
{ |
|
||||
// System.Drawing needs this.
|
|
||||
private Stream bmpStream; |
|
||||
private Image bmpDrawing; |
|
||||
private Image<Rgba32> bmpCore; |
|
||||
|
|
||||
[GlobalSetup] |
|
||||
public void ReadImages() |
|
||||
{ |
|
||||
if (this.bmpStream == null) |
|
||||
{ |
|
||||
this.bmpStream = File.OpenRead("../ImageSharp.Tests/TestImages/Formats/Bmp/Car.bmp"); |
|
||||
this.bmpCore = CoreImage.Load<Rgba32>(this.bmpStream); |
|
||||
this.bmpStream.Position = 0; |
|
||||
this.bmpDrawing = Image.FromStream(this.bmpStream); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[GlobalCleanup] |
|
||||
public void Cleanup() |
|
||||
{ |
|
||||
this.bmpStream.Dispose(); |
|
||||
this.bmpCore.Dispose(); |
|
||||
this.bmpDrawing.Dispose(); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Baseline = true, Description = "System.Drawing Gif")] |
|
||||
public void GifSystemDrawing() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
this.bmpDrawing.Save(memoryStream, ImageFormat.Gif); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Gif")] |
|
||||
public void GifCore() |
|
||||
{ |
|
||||
using (MemoryStream memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
this.bmpCore.SaveAsGif(memoryStream); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,54 +0,0 @@ |
|||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Collections.Generic; |
|
||||
using System.Drawing.Imaging; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
using BenchmarkDotNet.Jobs; |
|
||||
|
|
||||
using SixLabors.ImageSharp.Formats; |
|
||||
using SixLabors.ImageSharp.Formats.Gif; |
|
||||
|
|
||||
[Config(typeof(SingleRunConfig))] |
|
||||
public class EncodeGifMultiple : MultiImageBenchmarkBase.WithImagesPreloaded |
|
||||
{ |
|
||||
public class SingleRunConfig : Config |
|
||||
{ |
|
||||
public SingleRunConfig() |
|
||||
{ |
|
||||
this.Add( |
|
||||
Job.Default.WithLaunchCount(1) |
|
||||
.WithWarmupCount(1) |
|
||||
.WithTargetCount(1) |
|
||||
); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Params(InputImageCategory.AllImages)] |
|
||||
public override InputImageCategory InputCategory { get; set; } |
|
||||
|
|
||||
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Gif/" }; |
|
||||
|
|
||||
[Benchmark(Description = "EncodeGifMultiple - ImageSharp")] |
|
||||
public void EncodeGifImageSharp() |
|
||||
{ |
|
||||
this.ForEachImageSharpImage( |
|
||||
(img, ms) => |
|
||||
{ |
|
||||
img.Save(ms, new GifEncoder()); |
|
||||
return null; |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Baseline = true, Description = "EncodeGifMultiple - System.Drawing")] |
|
||||
public void EncodeGifSystemDrawing() |
|
||||
{ |
|
||||
this.ForEachSystemDrawingImage( |
|
||||
(img, ms) => |
|
||||
{ |
|
||||
img.Save(ms, ImageFormat.Gif); |
|
||||
return null; |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,83 +0,0 @@ |
|||||
// <copyright file="EncodePng.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Drawing; |
|
||||
using System.Drawing.Imaging; |
|
||||
using System.IO; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
using SixLabors.ImageSharp.Formats.Png; |
|
||||
using SixLabors.ImageSharp.Processing.Quantization; |
|
||||
using SixLabors.ImageSharp.Tests; |
|
||||
|
|
||||
using CoreImage = ImageSharp.Image; |
|
||||
|
|
||||
public class EncodePng : BenchmarkBase |
|
||||
{ |
|
||||
// System.Drawing needs this.
|
|
||||
private Stream bmpStream; |
|
||||
private Image bmpDrawing; |
|
||||
private Image<Rgba32> bmpCore; |
|
||||
|
|
||||
[Params(false)] |
|
||||
public bool LargeImage { get; set; } |
|
||||
|
|
||||
[Params(false)] |
|
||||
public bool UseOctreeQuantizer { get; set; } |
|
||||
|
|
||||
[GlobalSetup] |
|
||||
public void ReadImages() |
|
||||
{ |
|
||||
if (this.bmpStream == null) |
|
||||
{ |
|
||||
string path = Path.Combine( |
|
||||
TestEnvironment.InputImagesDirectoryFullPath, |
|
||||
this.LargeImage ? TestImages.Jpeg.Baseline.Jpeg420Exif : TestImages.Bmp.Car); |
|
||||
|
|
||||
|
|
||||
this.bmpStream = File.OpenRead(path); |
|
||||
this.bmpCore = CoreImage.Load<Rgba32>(this.bmpStream); |
|
||||
this.bmpStream.Position = 0; |
|
||||
this.bmpDrawing = Image.FromStream(this.bmpStream); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[GlobalCleanup] |
|
||||
public void Cleanup() |
|
||||
{ |
|
||||
this.bmpStream.Dispose(); |
|
||||
this.bmpCore.Dispose(); |
|
||||
this.bmpDrawing.Dispose(); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Baseline = true, Description = "System.Drawing Png")] |
|
||||
public void PngSystemDrawing() |
|
||||
{ |
|
||||
using (var memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
this.bmpDrawing.Save(memoryStream, ImageFormat.Png); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp Png")] |
|
||||
public void PngCore() |
|
||||
{ |
|
||||
using (var memoryStream = new MemoryStream()) |
|
||||
{ |
|
||||
IQuantizer quantizer = this.UseOctreeQuantizer |
|
||||
? |
|
||||
(IQuantizer)new OctreeQuantizer() |
|
||||
: new PaletteQuantizer(); |
|
||||
|
|
||||
var options = new PngEncoder { Quantizer = quantizer }; |
|
||||
this.bmpCore.SaveAsPng(memoryStream, options); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,41 +0,0 @@ |
|||||
// <copyright file="GetSetPixel.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image |
|
||||
{ |
|
||||
using System.Drawing; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
|
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
using SystemColor = System.Drawing.Color; |
|
||||
|
|
||||
public class GetSetPixel : BenchmarkBase |
|
||||
{ |
|
||||
[Benchmark(Baseline = true, Description = "System.Drawing GetSet pixel")] |
|
||||
public SystemColor ResizeSystemDrawing() |
|
||||
{ |
|
||||
using (Bitmap source = new Bitmap(400, 400)) |
|
||||
{ |
|
||||
source.SetPixel(200, 200, SystemColor.White); |
|
||||
return source.GetPixel(200, 200); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Description = "ImageSharp GetSet pixel")] |
|
||||
public Rgba32 ResizeCore() |
|
||||
{ |
|
||||
using (Image<Rgba32> image = new Image<Rgba32>(400, 400)) |
|
||||
{ |
|
||||
using (PixelAccessor<Rgba32> imagePixels = image.Lock()) |
|
||||
{ |
|
||||
imagePixels[200, 200] = Rgba32.White; |
|
||||
return imagePixels[200, 200]; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,44 +0,0 @@ |
|||||
// <copyright file="EncodeJpegMultiple.cs" company="James Jackson-South">
|
|
||||
// Copyright (c) James Jackson-South and contributors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
// </copyright>
|
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Benchmarks.Image.Jpeg |
|
||||
{ |
|
||||
using System.Collections.Generic; |
|
||||
using System.Drawing.Imaging; |
|
||||
|
|
||||
using BenchmarkDotNet.Attributes; |
|
||||
|
|
||||
using SixLabors.ImageSharp.Formats.Jpeg; |
|
||||
|
|
||||
[Config(typeof(Config.ShortClr))] // It's long enough to iterate through multiple files
|
|
||||
public class EncodeJpegMultiple : MultiImageBenchmarkBase.WithImagesPreloaded |
|
||||
{ |
|
||||
protected override IEnumerable<string> InputImageSubfoldersOrFiles => new[] { "Bmp/", "Jpg/baseline" }; |
|
||||
|
|
||||
protected override IEnumerable<string> SearchPatterns => new[] { "*.bmp", "*.jpg" }; |
|
||||
|
|
||||
[Benchmark(Description = "EncodeJpegMultiple - ImageSharp")] |
|
||||
public void EncodeJpegImageSharp() |
|
||||
{ |
|
||||
this.ForEachImageSharpImage( |
|
||||
(img, ms) => |
|
||||
{ |
|
||||
img.Save(ms, new JpegEncoder()); |
|
||||
return null; |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
[Benchmark(Baseline = true, Description = "EncodeJpegMultiple - System.Drawing")] |
|
||||
public void EncodeJpegSystemDrawing() |
|
||||
{ |
|
||||
this.ForEachSystemDrawingImage( |
|
||||
(img, ms) => |
|
||||
{ |
|
||||
img.Save(ms, ImageFormat.Jpeg); |
|
||||
return null; |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue