Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ImageSharp benchmark #2149

Merged
merged 24 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6f9a958
Initial version of ImageSharp
kunalspathak Nov 19, 2021
5daf1bf
Remove benchmark for Colorful
kunalspathak Nov 19, 2021
0ac04a7
Remove ImageMagick benchmarks
kunalspathak Nov 19, 2021
69d4abb
Remove some other benchmarks
kunalspathak Nov 19, 2021
9191f47
Copy TestUtilities
kunalspathak Nov 19, 2021
3e1b24c
Remove System.Drawing
kunalspathak Nov 19, 2021
2525791
Remove unneeded benchmarks:
kunalspathak Nov 19, 2021
5307234
Delete more benchmarks and non essential files with working model
kunalspathak Nov 19, 2021
664ab39
Remove Config files
kunalspathak Nov 19, 2021
0c998b9
Fix categories
kunalspathak Nov 19, 2021
873cb1f
Delete SIMD based divide/multiply for now:
kunalspathak Nov 19, 2021
2be5aa3
Add images
kunalspathak Nov 19, 2021
6f6ab6e
Delete one more benchmark
kunalspathak Nov 19, 2021
87d1fb3
Delete some webp images
kunalspathak Nov 19, 2021
8ab68c4
Trimmed more benchmarks based on review feedback
kunalspathak Dec 2, 2021
3315be9
review feedback
kunalspathak Aug 22, 2022
650d138
add resize and deleted some other
kunalspathak Aug 22, 2022
609f4a2
Upgrade Imagesharp to 2.1.3
kunalspathak Sep 19, 2022
c016e0f
Merge remote-tracking branch 'origin/main' into ImageSharp
kunalspathak Oct 28, 2022
210841e
review feedback
kunalspathak Oct 28, 2022
dae25ad
Update BDN and .NET to 7.0
kunalspathak Oct 28, 2022
e2a8ec8
Pass default CancellationToken
kunalspathak Oct 28, 2022
9732487
Remove Resize_Bicubic_Compare_Rgba32_Rgb24
kunalspathak Nov 4, 2022
8dc3758
Fix lint markdown error
kunalspathak Nov 4, 2022
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
39 changes: 39 additions & 0 deletions src/benchmarks/real-world/ImageSharp/Codecs/DecodeBmp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{

public class DecodeBmp
{
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(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);
}
}
}
60 changes: 60 additions & 0 deletions src/benchmarks/real-world/ImageSharp/Codecs/DecodeFilteredPng.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
public class DecodeFilteredPng
{
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(Description = "None-filtered PNG file")]
public Size PngFilter0()
=> LoadPng(this.filter0);

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

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

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

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

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

private static string TestImageFullPath(string path)
=> Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, path);
}
}
38 changes: 38 additions & 0 deletions src/benchmarks/real-world/ImageSharp/Codecs/DecodeGif.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
public class DecodeGif
{
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(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);
}
}
}
39 changes: 39 additions & 0 deletions src/benchmarks/real-world/ImageSharp/Codecs/DecodePng.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{

public class DecodePng
{
private byte[] pngBytes;

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

[Params(TestImages.Png.Splash)]
public string TestImage { get; set; }

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

[Benchmark(Description = "ImageSharp Png")]
public Size PngImageSharp()
{
using var memoryStream = new MemoryStream(this.pngBytes);
using var image = Image.Load<Rgba32>(memoryStream);
return image.Size();
}
}
}
32 changes: 32 additions & 0 deletions src/benchmarks/real-world/ImageSharp/Codecs/DecodeTga.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Formats.Tga;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
public class DecodeTga
{
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);

private byte[] data;

[Params(TestImages.Tga.Bit24BottomLeft)]
public string TestImage { get; set; }

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

[Benchmark(Description = "ImageSharp Tga")]
public int TgaImageSharp()
{
using var image = Image.Load<Bgr24>(this.data, new TgaDecoder());
return image.Width;
}
}
}
44 changes: 44 additions & 0 deletions src/benchmarks/real-world/ImageSharp/Codecs/EncodeBmp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
public class EncodeBmp
{
private Stream bmpStream;
private MemoryStream memoryStream = new MemoryStream();
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.memoryStream = new MemoryStream();
}
}

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

[Benchmark(Description = "ImageSharp Bmp")]
public void BmpImageSharp()
{
this.memoryStream.Seek(0, SeekOrigin.Begin);
this.bmpCore.SaveAsBmp(memoryStream);
}
}
}
58 changes: 58 additions & 0 deletions src/benchmarks/real-world/ImageSharp/Codecs/EncodeGif.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.

using System.IO;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Formats.Gif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
using SixLabors.ImageSharp.Tests;

namespace SixLabors.ImageSharp.Benchmarks.Codecs
{

public class EncodeGif
{
// System.Drawing needs this.
private Stream bmpStream;
private MemoryStream memoryStream = new MemoryStream();
private Image<Rgba32> bmpCore;

// Try to get as close to System.Drawing's output as possible
private readonly GifEncoder encoder = new GifEncoder
{
Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = KnownDitherings.Bayer4x4 })
};

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

[GlobalSetup]
public void ReadImages()
{
if (this.bmpStream == null)
{
this.bmpStream = File.OpenRead(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage));
this.bmpCore = Image.Load<Rgba32>(this.bmpStream);
this.bmpStream.Position = 0;
this.memoryStream = new MemoryStream();
}
}

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

[Benchmark(Description = "ImageSharp Gif")]
public void GifImageSharp()
{
this.memoryStream.Seek(0, SeekOrigin.Begin);
this.bmpCore.SaveAsGif(memoryStream, this.encoder);
}
}
}
Loading