Browse Source

Add decode webp benchmark

pull/1552/head
Brian Popow 6 years ago
parent
commit
263ff75d72
  1. 87
      tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs
  2. 3
      tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
  3. 2
      tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs
  4. 2
      tests/ImageSharp.Tests/TestImages.cs

87
tests/ImageSharp.Benchmarks/Codecs/DecodeWebp.cs

@ -0,0 +1,87 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using BenchmarkDotNet.Attributes;
using ImageMagick;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests;
namespace SixLabors.ImageSharp.Benchmarks.Codecs
{
[Config(typeof(Config.ShortClr))]
public class DecodeWebp : BenchmarkBase
{
private byte[] webpLossyBytes;
private byte[] webpLosslessBytes;
private string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImageLossy);
private string TestImageLosslessFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImageLossless);
[Params(TestImages.WebP.Lossy.Bike)]
public string TestImageLossy { get; set; }
[Params(TestImages.WebP.Lossless.BikeThreeTransforms)]
public string TestImageLossless { get; set; }
[GlobalSetup]
public void ReadImages()
{
if (this.webpLossyBytes is null)
{
this.webpLossyBytes = File.ReadAllBytes(this.TestImageLossyFullPath);
}
if (this.webpLosslessBytes is null)
{
this.webpLosslessBytes = File.ReadAllBytes(this.TestImageLosslessFullPath);
}
}
[Benchmark(Baseline = true, Description = "Magick Lossy WebP")]
public int WebpLossyMagick()
{
var settings = new MagickReadSettings { Format = MagickFormat.WebP };
using (var image = new MagickImage(new MemoryStream(this.webpLossyBytes), settings))
{
return image.Width;
}
}
[Benchmark(Description = "ImageSharp Lossy Webp")]
public int WebpLossy()
{
using (var memoryStream = new MemoryStream(this.webpLossyBytes))
{
using (var image = Image.Load<Rgba32>(memoryStream))
{
return image.Height;
}
}
}
[Benchmark(Baseline = true, Description = "Magick Lossless WebP")]
public int WebpLosslessMagick()
{
var settings = new MagickReadSettings { Format = MagickFormat.WebP };
using (var image = new MagickImage(new MemoryStream(this.webpLosslessBytes), settings))
{
return image.Width;
}
}
[Benchmark(Description = "ImageSharp Lossless Webp")]
public int WebpLossless()
{
using (var memoryStream = new MemoryStream(this.webpLosslessBytes))
{
using (var image = Image.Load<Rgba32>(memoryStream))
{
return image.Height;
}
}
}
}
}

3
tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
@ -16,6 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" />
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="Colourful" />
<PackageReference Include="SixLabors.Shapes.Text" />

2
tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs

@ -287,7 +287,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[WithFile(Lossless.ThreeTransforms5, PixelTypes.Rgba32)]
[WithFile(Lossless.ThreeTransforms6, PixelTypes.Rgba32)]
[WithFile(Lossless.ThreeTransforms7, PixelTypes.Rgba32)]
[WithFile(Lossless.ThreeTransforms8, PixelTypes.Rgba32)]
[WithFile(Lossless.BikeThreeTransforms, PixelTypes.Rgba32)]
public void WebpDecoder_CanDecode_Lossless_WithThreeTransforms<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

2
tests/ImageSharp.Tests/TestImages.cs

@ -416,7 +416,7 @@ namespace SixLabors.ImageSharp.Tests
public const string ThreeTransforms5 = "Webp/lossless_vec_2_11.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms6 = "Webp/lossless_vec_2_14.webp"; // substract_green, predictor, cross_color
public const string ThreeTransforms7 = "Webp/lossless_vec_2_15.webp"; // color_indexing, predictor, cross_color
public const string ThreeTransforms8 = "Webp/bike_lossless.webp"; // substract_green, predictor, cross_color
public const string BikeThreeTransforms = "Webp/bike_lossless.webp"; // substract_green, predictor, cross_color
// Invalid / corrupted images
// Below images have errors according to webpinfo. The error message webpinfo gives is "Truncated data detected when parsing RIFF payload."

Loading…
Cancel
Save