From 17bc2ad05f09b27d57f1d5b4c4ba59c9da431b1e Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 4 May 2016 17:59:57 +1000 Subject: [PATCH] Add benchmarking Former-commit-id: b49aa6d4012cc28d93b0f2c680d4de6d10aa09bb Former-commit-id: a59176e8bda26889d71fde5d239837bc0994ce79 Former-commit-id: 2a7361abe1a31ab578c0b85d0492eacea12cb8a4 --- .gitignore | 5 ++- ImageProcessorCore.sln | 15 +++++++ .../Properties/AssemblyInfo.cs | 1 + src/ImageProcessorCore/project.json | 9 +++- .../ImageProcessorCore.Benchmarks.xproj | 20 +++++++++ .../ImageProcessorCore.Benchmarks/Program.cs | 26 +++++++++++ .../Properties/AssemblyInfo.cs | 23 ++++++++++ tests/ImageProcessorCore.Benchmarks/Resize.cs | 44 +++++++++++++++++++ .../project.json | 29 ++++++++++++ 9 files changed, 169 insertions(+), 3 deletions(-) create mode 100644 tests/ImageProcessorCore.Benchmarks/ImageProcessorCore.Benchmarks.xproj create mode 100644 tests/ImageProcessorCore.Benchmarks/Program.cs create mode 100644 tests/ImageProcessorCore.Benchmarks/Properties/AssemblyInfo.cs create mode 100644 tests/ImageProcessorCore.Benchmarks/Resize.cs create mode 100644 tests/ImageProcessorCore.Benchmarks/project.json diff --git a/.gitignore b/.gitignore index 782616a571..b00bc712a0 100644 --- a/.gitignore +++ b/.gitignore @@ -205,4 +205,7 @@ FakesAssemblies/ # ASP.NET 5 project.lock.json -artifacts/ \ No newline at end of file +artifacts/ + +#BenchmarkDotNet +**/BenchmarkDotNet.Artifacts/ \ No newline at end of file diff --git a/ImageProcessorCore.sln b/ImageProcessorCore.sln index 5c82adba6e..f3677d892a 100644 --- a/ImageProcessorCore.sln +++ b/ImageProcessorCore.sln @@ -12,6 +12,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionItems", "SolutionIt README.md = README.md EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{56801022-D71A-4FBE-BC5B-CBA08E2284EC}" +EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageProcessorCore.Benchmarks", "tests\ImageProcessorCore.Benchmarks\ImageProcessorCore.Benchmarks.xproj", "{299D8E18-102C-42DE-ADBF-79098EE706A8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -26,8 +32,17 @@ 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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + 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} + EndGlobalSection EndGlobal diff --git a/src/ImageProcessorCore/Properties/AssemblyInfo.cs b/src/ImageProcessorCore/Properties/AssemblyInfo.cs index e093d9ba49..ea81ff60c6 100644 --- a/src/ImageProcessorCore/Properties/AssemblyInfo.cs +++ b/src/ImageProcessorCore/Properties/AssemblyInfo.cs @@ -30,4 +30,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyFileVersion("1.0.0.0")] // Ensure the internals can be tested. +[assembly: InternalsVisibleTo("ImageProcessorCore.Benchmarks")] [assembly: InternalsVisibleTo("ImageProcessorCore.Tests")] diff --git a/src/ImageProcessorCore/project.json b/src/ImageProcessorCore/project.json index 7a6913f70e..7bf53653b7 100644 --- a/src/ImageProcessorCore/project.json +++ b/src/ImageProcessorCore/project.json @@ -27,6 +27,11 @@ "Microsoft.NETCore.Platforms": "1.0.1-beta-23516" }, "frameworks": { - "dotnet5.5": { } + "dotnet5.5": { }, + "dnx46": { + "frameworkAssemblies": { + "System.Runtime": "4.0.0.0" + } + } } -} \ No newline at end of file +} diff --git a/tests/ImageProcessorCore.Benchmarks/ImageProcessorCore.Benchmarks.xproj b/tests/ImageProcessorCore.Benchmarks/ImageProcessorCore.Benchmarks.xproj new file mode 100644 index 0000000000..4e06339d40 --- /dev/null +++ b/tests/ImageProcessorCore.Benchmarks/ImageProcessorCore.Benchmarks.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 299d8e18-102c-42de-adbf-79098ee706a8 + ImageProcessorCore.Benchmarks + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/tests/ImageProcessorCore.Benchmarks/Program.cs b/tests/ImageProcessorCore.Benchmarks/Program.cs new file mode 100644 index 0000000000..fe674d9e06 --- /dev/null +++ b/tests/ImageProcessorCore.Benchmarks/Program.cs @@ -0,0 +1,26 @@ +namespace ImageProcessorCore.Benchmarks +{ + using System; + using System.Reflection; + + using BenchmarkDotNet.Attributes; + using BenchmarkDotNet.Running; + using System.Linq; + + public class Program + { + public static void Main(string[] args) + { + //Use reflection for a more maintainable way of creating the benchmark switcher, + Type[] benchmarks = typeof(Program).Assembly.GetTypes() + .Where(t => t.GetMethods(BindingFlags.Instance | BindingFlags.Public) + .Any(m => m.GetCustomAttributes(typeof(BenchmarkAttribute), false).Any())) + .OrderBy(t => t.Namespace) + .ThenBy(t => t.Name) + .ToArray(); + + BenchmarkSwitcher benchmarkSwitcher = new BenchmarkSwitcher(benchmarks); + benchmarkSwitcher.Run(args); + } + } +} diff --git a/tests/ImageProcessorCore.Benchmarks/Properties/AssemblyInfo.cs b/tests/ImageProcessorCore.Benchmarks/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..08636c3903 --- /dev/null +++ b/tests/ImageProcessorCore.Benchmarks/Properties/AssemblyInfo.cs @@ -0,0 +1,23 @@ +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: AssemblyTitle("ImageProcessorCore.Benchmarks")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ImageProcessorCore.Benchmarks")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 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("299d8e18-102c-42de-adbf-79098ee706a8")] diff --git a/tests/ImageProcessorCore.Benchmarks/Resize.cs b/tests/ImageProcessorCore.Benchmarks/Resize.cs new file mode 100644 index 0000000000..269904e620 --- /dev/null +++ b/tests/ImageProcessorCore.Benchmarks/Resize.cs @@ -0,0 +1,44 @@ +namespace ImageProcessorCore.Benchmarks +{ + using System.Drawing; + using System.Drawing.Drawing2D; + + using BenchmarkDotNet.Attributes; + + using ImageProcessorCore.Samplers; + using CoreImage = ImageProcessorCore.Image; + using CoreSize = ImageProcessorCore.Size; + + public class Resize + { + [Benchmark(Baseline = true, Description = "System Drawing Resize")] + public Size ResizeSystemDrawing() + { + using (Bitmap source = new Bitmap(400, 400)) + { + using (Bitmap destination = new Bitmap(100, 100)) + { + using (Graphics graphics = Graphics.FromImage(destination)) + { + graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + graphics.CompositingQuality = CompositingQuality.HighQuality; + graphics.DrawImage(source, 0, 0, 100, 100); + } + + return destination.Size; + } + } + } + + [Benchmark(Description = "ImageProcessor.Core Resize")] + public CoreSize ResizeCore() + { + using (CoreImage image = new CoreImage(400, 400)) + { + image.Resize(100, 100); + return new CoreSize(image.Width, image.Height); + } + } + } +} diff --git a/tests/ImageProcessorCore.Benchmarks/project.json b/tests/ImageProcessorCore.Benchmarks/project.json new file mode 100644 index 0000000000..a0a15d975e --- /dev/null +++ b/tests/ImageProcessorCore.Benchmarks/project.json @@ -0,0 +1,29 @@ +{ + "version": "1.0.0-*", + "description": "ImageProcessorCore.Benchmarks Console Application", + "authors": [ "James.South" ], + "tags": [ "" ], + "projectUrl": "", + "licenseUrl": "", + + "compilationOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "ImageProcessorCore": "1.0.0-*", + "BenchmarkDotNet": "0.9.5" + }, + + "commands": { + "ImageProcessorCore.Benchmarks": "ImageProcessorCore.Benchmarks" + }, + + "frameworks": { + "dnx46": { + "frameworkAssemblies": { + "System.Drawing": "4.0.0.0" + } + } + } +}