Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions tests/ImageSharp.Benchmarks/BenchmarkBase.cs

This file was deleted.

29 changes: 11 additions & 18 deletions tests/ImageSharp.Benchmarks/Codecs/DecodeBmp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodeBmp : BenchmarkBase
[Config(typeof(Config.ShortMultiFramework))]
public class DecodeBmp
{
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()
Expand All @@ -32,25 +33,17 @@ public void ReadImages()
[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;
}
}
using var memoryStream = new MemoryStream(this.bmpBytes);
using var image = SDImage.FromStream(memoryStream);
return image.Size;
}

[Benchmark(Description = "ImageSharp Bmp")]
public Size BmpCore()
public Size BmpImageSharp()
{
using (var memoryStream = new MemoryStream(this.bmpBytes))
{
using (var image = Image.Load<Rgba32>(memoryStream))
{
return new Size(image.Width, image.Height);
}
}
using var memoryStream = new MemoryStream(this.bmpBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return new Size(image.Width, image.Height);
}
}
}
48 changes: 18 additions & 30 deletions tests/ImageSharp.Benchmarks/Codecs/DecodeFilteredPng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;
using CoreSize = SixLabors.ImageSharp.Size;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodeFilteredPng : BenchmarkBase
[Config(typeof(Config.ShortMultiFramework))]
public class DecodeFilteredPng
{
private byte[] filter0;
private byte[] filter1;
Expand All @@ -30,44 +29,33 @@ public void ReadImages()
}

[Benchmark(Baseline = true, Description = "None-filtered PNG file")]
public CoreSize PngFilter0()
{
return LoadPng(this.filter0);
}
public Size PngFilter0()
=> LoadPng(this.filter0);

[Benchmark(Description = "Sub-filtered PNG file")]
public CoreSize PngFilter1()
{
return LoadPng(this.filter1);
}
public Size PngFilter1()
=> LoadPng(this.filter1);

[Benchmark(Description = "Up-filtered PNG file")]
public CoreSize PngFilter2()
{
return LoadPng(this.filter2);
}
public Size PngFilter2()
=> LoadPng(this.filter2);

[Benchmark(Description = "Average-filtered PNG file")]
public CoreSize PngFilter3()
{
return LoadPng(this.filter3);
}
public Size PngFilter3()
=> LoadPng(this.filter3);

[Benchmark(Description = "Paeth-filtered PNG file")]
public CoreSize PngFilter4()
{
return LoadPng(this.filter4);
}
public Size PngFilter4()
=> LoadPng(this.filter4);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static CoreSize LoadPng(byte[] bytes)
private static Size LoadPng(byte[] bytes)
{
using (var image = Image.Load<Rgba32>(bytes))
{
return image.Size();
}
using var image = Image.Load<Rgba32>(bytes);
return image.Size();
}

private static string TestImageFullPath(string path) => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, path);
private static string TestImageFullPath(string path)
=> Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, path);
}
}
}
29 changes: 11 additions & 18 deletions tests/ImageSharp.Benchmarks/Codecs/DecodeGif.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodeGif : BenchmarkBase
[Config(typeof(Config.ShortMultiFramework))]
public class DecodeGif
{
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()
Expand All @@ -32,25 +33,17 @@ public void ReadImages()
[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;
}
}
using var memoryStream = new MemoryStream(this.gifBytes);
using var image = SDImage.FromStream(memoryStream);
return image.Size;
}

[Benchmark(Description = "ImageSharp Gif")]
public Size GifCore()
public Size GifImageSharp()
{
using (var memoryStream = new MemoryStream(this.gifBytes))
{
using (var image = Image.Load<Rgba32>(memoryStream))
{
return new Size(image.Width, image.Height);
}
}
using var memoryStream = new MemoryStream(this.gifBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return new Size(image.Width, image.Height);
}
}
}
29 changes: 11 additions & 18 deletions tests/ImageSharp.Benchmarks/Codecs/DecodePng.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodePng : BenchmarkBase
[Config(typeof(Config.ShortMultiFramework))]
public class DecodePng
{
private byte[] pngBytes;

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

[Params(TestImages.Png.Splash)]
public string TestImage { get; set; }
Expand All @@ -32,25 +33,17 @@ public void ReadImages()
[Benchmark(Baseline = true, Description = "System.Drawing Png")]
public SDSize PngSystemDrawing()
{
using (var memoryStream = new MemoryStream(this.pngBytes))
{
using (var image = SDImage.FromStream(memoryStream))
{
return image.Size;
}
}
using var memoryStream = new MemoryStream(this.pngBytes);
using var image = SDImage.FromStream(memoryStream);
return image.Size;
}

[Benchmark(Description = "ImageSharp Png")]
public Size PngCore()
public Size PngImageSharp()
{
using (var memoryStream = new MemoryStream(this.pngBytes))
{
using (var image = Image.Load<Rgba32>(memoryStream))
{
return image.Size();
}
}
using var memoryStream = new MemoryStream(this.pngBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return image.Size();
}
}
}
34 changes: 11 additions & 23 deletions tests/ImageSharp.Benchmarks/Codecs/DecodeTga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.IO;
using System.Threading;
using BenchmarkDotNet.Attributes;

using ImageMagick;
using Pfim;
using SixLabors.ImageSharp.Formats.Tga;
Expand All @@ -14,8 +13,8 @@

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodeTga : BenchmarkBase
[Config(typeof(Config.ShortMultiFramework))]
public class DecodeTga
{
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);

Expand All @@ -28,47 +27,36 @@ public class DecodeTga : BenchmarkBase

[GlobalSetup]
public void SetupData()
{
this.data = File.ReadAllBytes(this.TestImageFullPath);
}
=> this.data = File.ReadAllBytes(this.TestImageFullPath);

[Benchmark(Baseline = true, Description = "ImageMagick Tga")]
public int TgaImageMagick()
{
var settings = new MagickReadSettings { Format = MagickFormat.Tga };
using (var image = new MagickImage(new MemoryStream(this.data), settings))
{
return image.Width;
}
using var image = new MagickImage(new MemoryStream(this.data), settings);
return image.Width;
}

[Benchmark(Description = "ImageSharp Tga")]
public int TgaCore()
public int TgaImageSharp()
{
using (var image = Image.Load<Bgr24>(this.data, new TgaDecoder()))
{
return image.Width;
}
using var image = Image.Load<Bgr24>(this.data, new TgaDecoder());
return image.Width;
}

[Benchmark(Description = "Pfim Tga")]
public int TgaPfim()
{
using (var image = Targa.Create(this.data, this.pfimConfig))
{
return image.Width;
}
using var image = Targa.Create(this.data, this.pfimConfig);
return image.Width;
}

private class PfimAllocator : IImageAllocator
{
private int rented;
private readonly ArrayPool<byte> shared = ArrayPool<byte>.Shared;

public byte[] Rent(int size)
{
return this.shared.Rent(size);
}
public byte[] Rent(int size) => this.shared.Rent(size);

public void Return(byte[] data)
{
Expand Down
23 changes: 10 additions & 13 deletions tests/ImageSharp.Benchmarks/Codecs/EncodeBmp.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors.
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.Drawing.Imaging;
Expand All @@ -10,8 +10,8 @@

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class EncodeBmp : BenchmarkBase
[Config(typeof(Config.ShortMultiFramework))]
public class EncodeBmp
{
private Stream bmpStream;
private SDImage bmpDrawing;
Expand All @@ -33,26 +33,23 @@ public void ReadImages()
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);
}
using var memoryStream = new MemoryStream();
this.bmpDrawing.Save(memoryStream, ImageFormat.Bmp);
}

[Benchmark(Description = "ImageSharp Bmp")]
public void BmpCore()
public void BmpImageSharp()
{
using (var memoryStream = new MemoryStream())
{
this.bmpCore.SaveAsBmp(memoryStream);
}
using var memoryStream = new MemoryStream();
this.bmpCore.SaveAsBmp(memoryStream);
}
}
}
}
Loading