Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add general multi-dimensional array test #60749

Merged
merged 1 commit into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
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>