diff options
author | Andy Ayers <andya@microsoft.com> | 2015-12-09 00:56:21 -0800 |
---|---|---|
committer | Andy Ayers <andya@microsoft.com> | 2015-12-09 00:56:21 -0800 |
commit | d2f53dc80b69e9c3add63f6753d80b91c0cc046d (patch) | |
tree | 6b5adaa2733da8bef686141be84dd76eb0a3d6b0 /tests | |
parent | c27ae7b93c527b2f2865d530f5b4286b09c245cb (diff) | |
parent | 47c421a21e63aa7065229d7b4bac069f58f6a58a (diff) | |
download | coreclr-d2f53dc80b69e9c3add63f6753d80b91c0cc046d.tar.gz coreclr-d2f53dc80b69e9c3add63f6753d80b91c0cc046d.tar.bz2 coreclr-d2f53dc80b69e9c3add63f6753d80b91c0cc046d.zip |
Merge pull request #2261 from AndyAyersMS/PerfTest4
More integer benchmarks for the jit
Diffstat (limited to 'tests')
10 files changed, 721 insertions, 0 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/Array2/Array2.cs b/tests/src/JIT/Performance/CodeQuality/BenchI/Array2/Array2.cs new file mode 100644 index 0000000000..6cfbe35fe7 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/Array2/Array2.cs @@ -0,0 +1,99 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.Xunit.Performance; +using System; +using System.Runtime.CompilerServices; +using Xunit; + +[assembly: OptimizeForBenchmarks] +[assembly: MeasureInstructionsRetired] + +public static class Array2 +{ + +#if DEBUG + public const int Iterations = 1; +#else + public const int Iterations = 500000; +#endif + + static T[][][] AllocArray<T>(int n1, int n2, int n3) { + T[][][] a = new T[n1][][]; + for (int i = 0; i < n1; ++i) { + a[i] = new T[n2][]; + for (int j = 0; j < n2; j++) { + a[i][j] = new T[n3]; + } + } + + return a; + } + + static void Initialize(int[][][] s) { + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 10; k++) { + s[i][j][k] = (2 * i) - (3 * j) + (5 * k); + } + } + } + } + + static bool VerifyCopy(int[][][] s, int[][][] d) { + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 10; k++) { + if (s[i][j][k] != d[i][j][k]) { + return false; + } + } + } + } + + return true; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static bool Bench(int loop) { + + int[][][] s = AllocArray<int>(10, 10, 10); + int[][][] d = AllocArray<int>(10, 10, 10); + + Initialize(s); + + for (; loop != 0; loop--) { + for (int i = 0; i < 10; i++) { + for (int j = 0; j < 10; j++) { + for (int k = 0; k < 10; k++) { + d[i][j][k] = s[i][j][k]; + } + } + } + } + + bool result = VerifyCopy(s, d); + + return result; + } + + [Benchmark] + public static void Test() { + foreach (var iteration in Benchmark.Iterations) { + using (iteration.StartMeasurement()) { + Bench(Iterations); + } + } + } + + static bool TestBase() { + bool result = Bench(Iterations); + return result; + } + + public static int Main() { + bool result = TestBase(); + return (result ? 100 : -1); + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/Array2/Array2.csproj b/tests/src/JIT/Performance/CodeQuality/BenchI/Array2/Array2.csproj new file mode 100644 index 0000000000..33a057d19a --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/Array2/Array2.csproj @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Array2.cs" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/IniArray/IniArray.cs b/tests/src/JIT/Performance/CodeQuality/BenchI/IniArray/IniArray.cs new file mode 100644 index 0000000000..55c8b9ab41 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/IniArray/IniArray.cs @@ -0,0 +1,59 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.Xunit.Performance; +using System; +using System.Runtime.CompilerServices; +using Xunit; + +[assembly: OptimizeForBenchmarks] +[assembly: MeasureInstructionsRetired] + +public static class IniArray +{ + +#if DEBUG + public const int Iterations = 1; +#else + public const int Iterations = 10000000; +#endif + + const int Allotted = 16; + static volatile object VolatileObject; + + static void Escape(object obj) { + VolatileObject = obj; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static bool Bench() { + char[] workarea = new char[Allotted]; + for (int i = 0; i < Iterations; i++) { + for (int j = 0; j < Allotted; j++) { + workarea[j] = ' '; + } + } + Escape(workarea); + return true; + } + + [Benchmark] + public static void Test() { + foreach (var iteration in Benchmark.Iterations) { + using (iteration.StartMeasurement()) { + Bench(); + } + } + } + + static bool TestBase() { + bool result = Bench(); + return result; + } + + public static int Main() { + bool result = TestBase(); + return (result ? 100 : -1); + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/IniArray/IniArray.csproj b/tests/src/JIT/Performance/CodeQuality/BenchI/IniArray/IniArray.csproj new file mode 100644 index 0000000000..4cdbdea375 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/IniArray/IniArray.csproj @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="IniArray.cs" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/LogicArray/LogicArray.cs b/tests/src/JIT/Performance/CodeQuality/BenchI/LogicArray/LogicArray.cs new file mode 100644 index 0000000000..22bf13a960 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/LogicArray/LogicArray.cs @@ -0,0 +1,96 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.Xunit.Performance; +using System; +using System.Runtime.CompilerServices; +using Xunit; + +[assembly: OptimizeForBenchmarks] +[assembly: MeasureInstructionsRetired] + +public static class LogicArray +{ + +#if DEBUG + public const int Iterations = 1; +#else + public const int Iterations = 3000; +#endif + + const int ArraySize = 50; + + struct Workarea + { + public int X; + public int[][] A; + } + + static T[][] AllocArray<T>(int n1, int n2) { + T[][] a = new T[n1][]; + for (int i = 0; i < n1; ++i) { + a[i] = new T[n2]; + } + return a; + } + + static bool Inner(ref Workarea cmn) { + int i, j, k; + cmn.X = 0; + for (i = 1; i <= 50; i++) { + for (j = 1; j <= 50; j++) { + cmn.A[i][j] = 1; + } + } + for (k = 1; k <= 50; k++) { + for (j = 1; j <= 50; j++) { + i = 1; + do { + cmn.X = cmn.X | cmn.A[i][j] & cmn.A[i + 1][k]; + i = i + 2; + } while (i <= 50); + } + } + if (cmn.X != 1) { + return false; + } + else { + return true; + } + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static bool Bench() { + Workarea cmn = new Workarea(); + cmn.X = 0; + cmn.A = AllocArray<int>(51, 51); + for (int n = 1; n <= Iterations; n++) { + bool result = Inner(ref cmn); + if (!result) { + return false; + } + } + + return true; + } + + [Benchmark] + public static void Test() { + foreach (var iteration in Benchmark.Iterations) { + using (iteration.StartMeasurement()) { + Bench(); + } + } + } + + static bool TestBase() { + bool result = Bench(); + return result; + } + + public static int Main() { + bool result = TestBase(); + return (result ? 100 : -1); + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/LogicArray/LogicArray.csproj b/tests/src/JIT/Performance/CodeQuality/BenchI/LogicArray/LogicArray.csproj new file mode 100644 index 0000000000..1f458391ef --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/LogicArray/LogicArray.csproj @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="LogicArray.cs" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/Midpoint/Midpoint.cs b/tests/src/JIT/Performance/CodeQuality/BenchI/Midpoint/Midpoint.cs new file mode 100644 index 0000000000..eac8f25c2f --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/Midpoint/Midpoint.cs @@ -0,0 +1,103 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.Xunit.Performance; +using System; +using System.Runtime.CompilerServices; +using Xunit; + +[assembly: OptimizeForBenchmarks] +[assembly: MeasureInstructionsRetired] + +public static class Midpoint +{ + +#if DEBUG + public const int Iterations = 1; +#else + public const int Iterations = 70000; +#endif + + static T[][] AllocArray<T>(int n1, int n2) { + T[][] a = new T[n1][]; + for (int i = 0; i < n1; ++i) { + a[i] = new T[n2]; + } + return a; + } + + static int Inner(ref int x, ref int y, ref int z) { + int mid; + + if (x < y) { + if (y < z) { + mid = y; + } + else { + if (x < z) { + mid = z; + } + else { + mid = x; + } + } + } + else { + if (x < z) { + mid = x; + } + else { + if (y < z) { + mid = z; + } + else { + mid = y; + } + } + } + + return (mid); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static bool Bench() { + int[][] a = AllocArray<int>(2001, 4); + int[] mid = new int[2001]; + int j = 99999; + + for (int i = 1; i <= 2000; i++) { + a[i][1] = j & 32767; + a[i][2] = (j + 11111) & 32767; + a[i][3] = (j + 22222) & 32767; + j = j + 33333; + } + + for (int k = 1; k <= Iterations; k++) { + for (int l = 1; l <= 2000; l++) { + mid[l] = Inner(ref a[l][1], ref a[l][2], ref a[l][3]); + } + } + + return (mid[2000] == 17018); + } + + [Benchmark] + public static void Test() { + foreach (var iteration in Benchmark.Iterations) { + using (iteration.StartMeasurement()) { + Bench(); + } + } + } + + static bool TestBase() { + bool result = Bench(); + return result; + } + + public static int Main() { + bool result = TestBase(); + return (result ? 100 : -1); + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/Midpoint/Midpoint.csproj b/tests/src/JIT/Performance/CodeQuality/BenchI/Midpoint/Midpoint.csproj new file mode 100644 index 0000000000..f0e3554950 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/Midpoint/Midpoint.csproj @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Midpoint.cs" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/MulMatrix/MulMatrix.cs b/tests/src/JIT/Performance/CodeQuality/BenchI/MulMatrix/MulMatrix.cs new file mode 100644 index 0000000000..b4275b62e4 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/MulMatrix/MulMatrix.cs @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.Xunit.Performance; +using System; +using System.Runtime.CompilerServices; +using Xunit; + +[assembly: OptimizeForBenchmarks] +[assembly: MeasureInstructionsRetired] + +public static class MulMatrix +{ + +#if DEBUG + public const int Iterations = 1; +#else + public const int Iterations = 100; +#endif + + const int Size = 75; + static volatile object VolatileObject; + + static void Escape(object obj) { + VolatileObject = obj; + } + + static T[][] AllocArray<T>(int n1, int n2) { + T[][] a = new T[n1][]; + for (int i = 0; i < n1; ++i) { + a[i] = new T[n2]; + } + return a; + } + + static void Inner(int[][] a, int[][] b, int[][] c) { + + int i, j, k, l; + + // setup + for (j = 0; j < Size; j++) { + for (i = 0; i < Size; i++) { + a[i][j] = i; + b[i][j] = 2 * j; + c[i][j] = a[i][j] + b[i][j]; + } + } + + // jkl + for (j = 0; j < Size; j++) { + for (k = 0; k < Size; k++) { + for (l = 0; l < Size; l++) { + c[j][k] += a[j][l] * b[l][k]; + } + } + } + + // jlk + for (j = 0; j < Size; j++) { + for (l = 0; l < Size; l++) { + for (k = 0; k < Size; k++) { + c[j][k] += a[j][l] * b[l][k]; + } + } + } + + // kjl + for (k = 0; k < Size; k++) { + for (j = 0; j < Size; j++) { + for (l = 0; l < Size; l++) { + c[j][k] += a[j][l] * b[l][k]; + } + } + } + + // klj + for (k = 0; k < Size; k++) { + for (l = 0; l < Size; l++) { + for (j = 0; j < Size; j++) { + c[j][k] += a[j][l] * b[l][k]; + } + } + } + + // ljk + for (l = 0; l < Size; l++) { + for (j = 0; j < Size; j++) { + for (k = 0; k < Size; k++) { + c[j][k] += a[j][l] * b[l][k]; + } + } + } + + // lkj + for (l = 0; l < Size; l++) { + for (k = 0; k < Size; k++) { + for (j = 0; j < Size; j++) { + c[j][k] += a[j][l] * b[l][k]; + } + } + } + + return; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + static bool Bench() { + int[][] a = AllocArray<int>(Size, Size); + int[][] b = AllocArray<int>(Size, Size); + int[][] c = AllocArray<int>(Size, Size); + + for (int i = 0; i < Iterations; ++i) { + Inner(a, b, c); + } + + Escape(c); + return true; + } + + [Benchmark] + public static void Test() { + foreach (var iteration in Benchmark.Iterations) { + using (iteration.StartMeasurement()) { + Bench(); + } + } + } + + static bool TestBase() { + bool result = Bench(); + return result; + } + + public static int Main() { + bool result = TestBase(); + return (result ? 100 : -1); + } +} diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/MulMatrix/MulMatrix.csproj b/tests/src/JIT/Performance/CodeQuality/BenchI/MulMatrix/MulMatrix.csproj new file mode 100644 index 0000000000..441c2f2f09 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchI/MulMatrix/MulMatrix.csproj @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <FileAlignment>512</FileAlignment> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <ItemGroup> + <Compile Include="MulMatrix.cs" /> + </ItemGroup> + <PropertyGroup> + <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson> + <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson> + </PropertyGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project> |