diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs index 70ddb3000..3bf7ed92b 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegTests.cs +++ b/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 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(TestImageProvider provider, JpegSubsample subSample, int quality) where TColor : struct, IPackedPixel, IEquatable { diff --git a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs index c045d8937..56ca0d0a7 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/ReferenceImplementations.cs @@ -8,7 +8,7 @@ namespace ImageSharp.Tests using ImageSharp.Formats; using ImageSharp.Formats.Jpg; - + /// /// 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 diff --git a/tests/ImageSharp.Tests/Formats/Jpg/UtilityTestClassBase.cs b/tests/ImageSharp.Tests/Formats/Jpg/UtilityTestClassBase.cs index 74c6772b7..650b9fc07 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/UtilityTestClassBase.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/UtilityTestClassBase.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests /// /// Utility class to measure the execution of an operation. /// - public class MeasureFixture + public class MeasureFixture : TestBase { protected bool EnablePrinting = true; diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index aab7c2620..892e344d6 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/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)); }); } diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index e5b46b0e1..7265e45a4 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/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, }; diff --git a/tests/ImageSharp.Tests46/TestFile.cs b/tests/ImageSharp.Tests46/TestFile.cs index 95e2fc083..1b9842857 100644 --- a/tests/ImageSharp.Tests46/TestFile.cs +++ b/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) =>