Browse Source

Benchmark_JpegDecoder

af/merge-core
Anton Firszov 9 years ago
parent
commit
124daec0bf
  1. 32
      tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs
  2. 7
      tests/ImageSharp.Tests/TestFile.cs
  3. 2
      tests/ImageSharp.Tests/TestImages.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(
40,
() =>
{
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>
{

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,
};

Loading…
Cancel
Save