Browse Source

Benchmark_JpegDecoder

af/merge-core
antonfirsov 9 years ago
parent
commit
5e09f80db3
  1. 32
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  2. 2
      tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs
  3. 2
      tests/ImageSharp.Tests/Formats/Jpg/UtilityTestClassBase.cs
  4. 7
      tests/ImageSharp.Tests/TestFile.cs
  5. 2
      tests/ImageSharp.Tests/TestImages.cs
  6. 7
      tests/ImageSharp.Tests46/TestFile.cs

32
tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs

@ -13,13 +13,11 @@ namespace ImageSharp.Tests
using ImageSharp.Formats.Jpg;
public class JpegTests
public class JpegTests : MeasureFixture
{
private ITestOutputHelper Output { get; }
public JpegTests(ITestOutputHelper output)
: base(output)
{
this.Output = output;
}
public static IEnumerable<string> AllJpegFiles => TestImages.Jpeg.All;
@ -62,7 +60,7 @@ namespace ImageSharp.Tests
private const int BenchmarkExecTimes = 30;
public static readonly string[] BenchmarkFiles =
public static readonly string[] EncoderBenchmarkFiles =
{
TestImages.Bmp.Car, TestImages.Bmp.NegHeight,
TestImages.Bmp.F, TestImages.Png.Splash,
@ -72,11 +70,31 @@ namespace ImageSharp.Tests
private const PixelTypes BenchmarkPixels = PixelTypes.StandardImageClass; //PixelTypes.Color | PixelTypes.Argb;
[Theory] // Benchmark, enable manually
[InlineData(TestImages.Jpeg.Cmyk)]
[InlineData(TestImages.Jpeg.Ycck)]
[InlineData(TestImages.Jpeg.Calliphora)]
[InlineData(TestImages.Jpeg.Jpeg400)]
[InlineData(TestImages.Jpeg.Jpeg420)]
[InlineData(TestImages.Jpeg.Jpeg444)]
public void Benchmark_JpegDecoder(string fileName)
{
string path = TestFile.GetPath(fileName);
byte[] bytes = File.ReadAllBytes(path);
this.Measure(
100,
() =>
{
Image img = new Image(bytes);
},
$"Decode {fileName}");
}
//[Theory] // Benchmark, enable manually
[WithFileCollection(nameof(BenchmarkFiles), BenchmarkPixels, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(BenchmarkFiles), BenchmarkPixels, JpegSubsample.Ratio444, 75)]
[WithFileCollection(nameof(EncoderBenchmarkFiles), BenchmarkPixels, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(EncoderBenchmarkFiles), BenchmarkPixels, JpegSubsample.Ratio444, 75)]
public void Benchmark_JpegEncoder<TColor>(TestImageProvider<TColor> provider, JpegSubsample subSample, int quality)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{

2
tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs

@ -8,7 +8,7 @@ namespace ImageSharp.Tests
using ImageSharp.Formats;
using ImageSharp.Formats.Jpg;
/// <summary>
/// This class contains simplified (unefficient) reference implementations to produce verification data for unit tests
/// Floating point DCT code Ported from https://github.com/norishigefukushima/dct_simd

2
tests/ImageSharp.Tests/Formats/Jpg/UtilityTestClassBase.cs

@ -15,7 +15,7 @@ namespace ImageSharp.Tests
/// <summary>
/// Utility class to measure the execution of an operation.
/// </summary>
public class MeasureFixture
public class MeasureFixture : TestBase
{
protected bool EnablePrinting = true;

7
tests/ImageSharp.Tests/TestFile.cs

@ -34,12 +34,17 @@ namespace ImageSharp.Tests
this.Bytes = File.ReadAllBytes(file);
this.image = new Image(this.Bytes);
}
public static string GetPath(string file)
{
return Path.Combine(FormatsDirectory, file);
}
public static TestFile Create(string file)
{
return cache.GetOrAdd(file, (string fileName) =>
{
return new TestFile(FormatsDirectory + fileName);
return new TestFile(GetPath(file));
});
}

2
tests/ImageSharp.Tests/TestImages.cs

@ -56,7 +56,7 @@ namespace ImageSharp.Tests
public const string Jpeg444 = "Jpg/baseline/jpeg444.jpg";
public static readonly string[] All = {
Cmyk, Exif, Floorplan, Calliphora, Turtle, Fb, Progress, GammaDalaiLamaGray,
Cmyk, Ycck, Exif, Floorplan, Calliphora, Turtle, Fb, Progress, GammaDalaiLamaGray,
Festzug, Hiyamugi,
Jpeg400, Jpeg420, Jpeg444,
};

7
tests/ImageSharp.Tests46/TestFile.cs

@ -28,7 +28,12 @@ namespace ImageSharp.Tests
this.Bytes = File.ReadAllBytes(file);
this.image = new Image(this.Bytes);
}
public static string GetPath(string file)
{
return Path.Combine(FormatsDirectory, file);
}
public static TestFile Create(string file)
{
return cache.GetOrAdd(file, (string fileName) =>

Loading…
Cancel
Save