-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add general multi-dimensional array test (#60749)
This is similar to MDArray2, but uses the GetLowerBound/GetUpperBound APIs, and has a test case that uses non-zero lower bounds. It's in the benchmarks folder as it can be used as a benchmark to compare against MDArray2 behavior.
- Loading branch information
1 parent
4b0be56
commit ce4dd5f
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/tests/JIT/Performance/CodeQuality/Benchstones/MDBenchI/MDGeneralArray/MDGeneralArray.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
// | ||
|
||
using System.Runtime.CompilerServices; | ||
|
||
namespace Benchstone.MDBenchI | ||
{ | ||
public static class MDGeneralArray | ||
{ | ||
#if DEBUG | ||
public const int Iterations = 1; | ||
#else | ||
public const int Iterations = 5000; | ||
#endif | ||
|
||
static void Initialize(int[,,] s) { | ||
for (int i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++) { | ||
for (int j = s.GetLowerBound(1); j <= s.GetUpperBound(1); j++) { | ||
for (int k = s.GetLowerBound(2); k <= s.GetUpperBound(2); k++) { | ||
s[i,j,k] = (2 * i) - (3 * j) + (5 * k); | ||
} | ||
} | ||
} | ||
} | ||
|
||
static bool VerifyCopy(int[,,] s, int[,,] d) { | ||
for (int i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++) { | ||
for (int j = s.GetLowerBound(1); j <= s.GetUpperBound(1); j++) { | ||
for (int k = s.GetLowerBound(2); k <= s.GetUpperBound(2); k++) { | ||
if (s[i,j,k] != d[i,j,k]) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
static bool Bench(int loop, int[,,] s, int[,,] d) { | ||
|
||
Initialize(s); | ||
|
||
for (; loop != 0; loop--) { | ||
for (int i = s.GetLowerBound(0); i <= s.GetUpperBound(0); i++) { | ||
for (int j = s.GetLowerBound(1); j <= s.GetUpperBound(1); j++) { | ||
for (int k = s.GetLowerBound(2); k <= s.GetUpperBound(2); k++) { | ||
d[i,j,k] = s[i,j,k]; | ||
} | ||
} | ||
} | ||
} | ||
|
||
bool result = VerifyCopy(s, d); | ||
|
||
return result; | ||
} | ||
|
||
public static bool Test() { | ||
int[,,] s = new int[10, 10, 10]; | ||
int[,,] d = new int[10, 10, 10]; | ||
return Bench(Iterations, s, d); | ||
} | ||
|
||
public static bool Test2() { | ||
int[] lengths = new int[3] { 10, 10, 10 }; | ||
int[] lowerBounds = new int[3] { -5, 0, 5 }; | ||
int[,,] s = (int[,,])System.Array.CreateInstance(typeof(int), lengths, lowerBounds); | ||
int[,,] d = (int[,,])System.Array.CreateInstance(typeof(int), lengths, lowerBounds); | ||
return Bench(Iterations, s, d); | ||
} | ||
|
||
public static int Main() { | ||
bool result = Test() && Test2(); | ||
return (result ? 100 : -1); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...sts/JIT/Performance/CodeQuality/Benchstones/MDBenchI/MDGeneralArray/MDGeneralArray.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<ProjectAssetsFile>$(JitPackagesConfigFileDirectory)benchmark\obj\project.assets.json</ProjectAssetsFile> | ||
</PropertyGroup> | ||
</Project> |