From d90b6e5b95190960b5848d2ae355e45d3fbfc262 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Thu, 17 Nov 2016 00:20:47 +0100 Subject: [PATCH] JpegBenchmark --- ImageSharp.sln | 14 ++-- .../Formats/Jpg/Components/Block8x8F.cs | 15 ++++- tests/JpegBenchmark/JpegBenchmark.xproj | 21 ++++++ tests/JpegBenchmark/Program.cs | 65 +++++++++++++++++++ .../JpegBenchmark/Properties/AssemblyInfo.cs | 19 ++++++ tests/JpegBenchmark/project.json | 21 ++++++ 6 files changed, 147 insertions(+), 8 deletions(-) create mode 100644 tests/JpegBenchmark/JpegBenchmark.xproj create mode 100644 tests/JpegBenchmark/Program.cs create mode 100644 tests/JpegBenchmark/Properties/AssemblyInfo.cs create mode 100644 tests/JpegBenchmark/project.json diff --git a/ImageSharp.sln b/ImageSharp.sln index abf624293..b25388422 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -7,8 +7,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp", "src\ImageShar EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Tests", "tests\ImageSharp.Tests\ImageSharp.Tests.xproj", "{F836E8E6-B4D9-4208-8346-140C74678B91}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Benchmarks", "tests\ImageSharp.Benchmarks\ImageSharp.Benchmarks.xproj", "{299D8E18-102C-42DE-ADBF-79098EE706A8}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionItems", "{C317F1B1-D75E-4C6D-83EB-80367343E0D7}" ProjectSection(SolutionItems) = preProject build\appveyor-project-version-patch.js = build\appveyor-project-version-patch.js @@ -25,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C06 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{56801022-D71A-4FBE-BC5B-CBA08E2284EC}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "JpegBenchmark", "tests\JpegBenchmark\JpegBenchmark.xproj", "{7C69F09A-3286-45A1-BED2-B9C628150FA9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,10 +39,10 @@ Global {F836E8E6-B4D9-4208-8346-140C74678B91}.Debug|Any CPU.Build.0 = Debug|Any CPU {F836E8E6-B4D9-4208-8346-140C74678B91}.Release|Any CPU.ActiveCfg = Release|Any CPU {F836E8E6-B4D9-4208-8346-140C74678B91}.Release|Any CPU.Build.0 = Release|Any CPU - {299D8E18-102C-42DE-ADBF-79098EE706A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {299D8E18-102C-42DE-ADBF-79098EE706A8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {299D8E18-102C-42DE-ADBF-79098EE706A8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {299D8E18-102C-42DE-ADBF-79098EE706A8}.Release|Any CPU.Build.0 = Release|Any CPU + {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C69F09A-3286-45A1-BED2-B9C628150FA9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -50,6 +50,6 @@ Global GlobalSection(NestedProjects) = preSolution {2AA31A1F-142C-43F4-8687-09ABCA4B3A26} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {F836E8E6-B4D9-4208-8346-140C74678B91} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} - {299D8E18-102C-42DE-ADBF-79098EE706A8} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} + {7C69F09A-3286-45A1-BED2-B9C628150FA9} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} EndGlobalSection EndGlobal diff --git a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs b/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs index 73d71b282..4b9830aa7 100644 --- a/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs +++ b/src/ImageSharp46/Formats/Jpg/Components/Block8x8F.cs @@ -491,6 +491,19 @@ namespace ImageSharp.Formats } } - + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal static unsafe void UnZig(Block8x8F* block, Block8x8F* qt, int* unzigPtr) + { + float* b = (float*)block; + float* qtp = (float*)qt; + for (int zig = 0; zig < BlockF.BlockSize; zig++) + { + float* unzigPos = b + unzigPtr[zig]; + float val = *unzigPos; + val *= qtp[zig]; + *unzigPos = val; + } + } } } \ No newline at end of file diff --git a/tests/JpegBenchmark/JpegBenchmark.xproj b/tests/JpegBenchmark/JpegBenchmark.xproj new file mode 100644 index 000000000..99938acf4 --- /dev/null +++ b/tests/JpegBenchmark/JpegBenchmark.xproj @@ -0,0 +1,21 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 7c69f09a-3286-45a1-bed2-b9c628150fa9 + JpegBenchmark + .\obj + .\bin\ + v4.5.2 + + + + 2.0 + + + diff --git a/tests/JpegBenchmark/Program.cs b/tests/JpegBenchmark/Program.cs new file mode 100644 index 000000000..260a0e4e5 --- /dev/null +++ b/tests/JpegBenchmark/Program.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Reflection; +using System.Threading.Tasks; +using ImageSharp; + +namespace JpegBenchmark +{ + public class Program + { + private const string TestImageDir = @"../ImageSharp.Tests/TestImages/Formats/Jpg"; + + private static byte[][] ReadAllFiles() + { + var files = Directory.EnumerateFiles(TestImageDir).ToArray(); + return files.Select(File.ReadAllBytes).ToArray(); + } + + public static void Main(string[] args) + { + var allData = ReadAllFiles(); + int times; + if (args.Length == 0 || !int.TryParse(args[0], out times)) + { + times = 20; + } + + Console.WriteLine($"Vector.IsHardwareAccelerated == {Vector.IsHardwareAccelerated}"); + + Console.WriteLine($"Decoding {allData.Length} jpegs X {times} times ..."); + + double estimatedTotalBlockCount = 0; + + Stopwatch sw = Stopwatch.StartNew(); + for (int i = 0; i < times; i++) + { + estimatedTotalBlockCount = DecodeAll(allData); + } + + sw.Stop(); + + Console.WriteLine($"Completed in {sw.ElapsedMilliseconds} ms"); + + Console.WriteLine($"Estimated block count: {estimatedTotalBlockCount}"); + Console.ReadLine(); + } + + private static double DecodeAll(byte[][] allData) + { + double estimatedTotalBlockCount = 0; + foreach (byte[] data in allData) + { + var stream = new MemoryStream(data); + Image img = new Image(stream); + + estimatedTotalBlockCount += img.Width*img.Height/64.0; + } + return estimatedTotalBlockCount; + } + } +} diff --git a/tests/JpegBenchmark/Properties/AssemblyInfo.cs b/tests/JpegBenchmark/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..aafacab2b --- /dev/null +++ b/tests/JpegBenchmark/Properties/AssemblyInfo.cs @@ -0,0 +1,19 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Sapa")] +[assembly: AssemblyProduct("JpegBenchmark")] +[assembly: AssemblyTrademark("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7c69f09a-3286-45a1-bed2-b9c628150fa9")] diff --git a/tests/JpegBenchmark/project.json b/tests/JpegBenchmark/project.json new file mode 100644 index 000000000..dca63dcd3 --- /dev/null +++ b/tests/JpegBenchmark/project.json @@ -0,0 +1,21 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true, + "optimize": true + }, + + "dependencies": { + "ImageSharp": "1.0.0-*", + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + } + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + } +}