-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C# multi-dimension array versions of the Benchstones tests (#60192)
* Add C# multi-dimension array versions of the Benchstones tests The Benchstones tests using multi-dimension arrays currently are implemented using C# "jagged" arrays. Add versions of the tests that use true C# multi-dimensional arrays. The code is exactly the same, except for the array creation and indexing. This will allow us to compare code generated for each, as well as to verify functionality. I intend to add versions of these to the microbenchmarks in the https://github.com/dotnet/performance repo as well. * Fix MDPuzzle build
- Loading branch information
1 parent
debe671
commit df42364
Showing
28 changed files
with
2,619 additions
and
2 deletions.
There are no files selected for viewing
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
125 changes: 125 additions & 0 deletions
125
src/tests/JIT/Performance/CodeQuality/Benchstones/MDBenchF/MDInProd/MDInProd.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,125 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// | ||
|
||
using Microsoft.Xunit.Performance; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Xunit; | ||
|
||
[assembly: OptimizeForBenchmarks] | ||
|
||
namespace Benchstone.MDBenchF | ||
{ | ||
public static class MDInProd | ||
{ | ||
#if DEBUG | ||
public const int Iterations = 1; | ||
#else | ||
public const int Iterations = 70; | ||
#endif | ||
|
||
private const int RowSize = 10 * Iterations; | ||
|
||
private static int s_seed; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static bool Bench() | ||
{ | ||
double[,] rma = new double[RowSize, RowSize]; | ||
double[,] rmb = new double[RowSize, RowSize]; | ||
double[,] rmr = new double[RowSize, RowSize]; | ||
|
||
double sum; | ||
|
||
Inner(rma, rmb, rmr); | ||
|
||
for (int i = 1; i < RowSize; i++) | ||
{ | ||
for (int j = 1; j < RowSize; j++) | ||
{ | ||
sum = 0; | ||
for (int k = 1; k < RowSize; k++) | ||
{ | ||
sum = sum + rma[i,k] * rmb[k,j]; | ||
} | ||
if (rmr[i,j] != sum) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static void InitRand() | ||
{ | ||
s_seed = 7774755; | ||
} | ||
|
||
private static int Rand() | ||
{ | ||
s_seed = (s_seed * 77 + 13218009) % 3687091; | ||
return s_seed; | ||
} | ||
|
||
private static void InitMatrix(double[,] m) | ||
{ | ||
for (int i = 1; i < RowSize; i++) | ||
{ | ||
for (int j = 1; j < RowSize; j++) | ||
{ | ||
m[i,j] = (Rand() % 120 - 60) / 3; | ||
} | ||
} | ||
} | ||
|
||
private static void InnerProduct(out double result, double[,] a, double[,] b, int row, int col) | ||
{ | ||
result = 0.0; | ||
for (int i = 1; i < RowSize; i++) | ||
{ | ||
result = result + a[row,i] * b[i,col]; | ||
} | ||
} | ||
|
||
private static void Inner(double[,] rma, double[,] rmb, double[,] rmr) | ||
{ | ||
InitRand(); | ||
InitMatrix(rma); | ||
InitMatrix(rmb); | ||
for (int i = 1; i < RowSize; i++) | ||
{ | ||
for (int j = 1; j < RowSize; j++) | ||
{ | ||
InnerProduct(out rmr[i,j], rma, rmb, i, j); | ||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public static void Test() | ||
{ | ||
foreach (var iteration in Benchmark.Iterations) | ||
{ | ||
using (iteration.StartMeasurement()) | ||
{ | ||
Bench(); | ||
} | ||
} | ||
} | ||
|
||
private static bool TestBase() | ||
{ | ||
bool result = Bench(); | ||
return result; | ||
} | ||
|
||
public static int Main() | ||
{ | ||
bool result = TestBase(); | ||
return (result ? 100 : -1); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tests/JIT/Performance/CodeQuality/Benchstones/MDBenchF/MDInProd/MDInProd.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> |
128 changes: 128 additions & 0 deletions
128
src/tests/JIT/Performance/CodeQuality/Benchstones/MDBenchF/MDInvMt/MDInvMt.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,128 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// | ||
// Solution of linear algebraic equations and matrix inversion. | ||
|
||
using Microsoft.Xunit.Performance; | ||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Xunit; | ||
|
||
[assembly: OptimizeForBenchmarks] | ||
|
||
namespace Benchstone.MDBenchF | ||
{ | ||
public static class MDInvMt | ||
{ | ||
#if DEBUG | ||
public const int Iterations = 1; | ||
#else | ||
public const int Iterations = 80; | ||
#endif | ||
|
||
private const int MatSize = Iterations; | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static bool Bench() | ||
{ | ||
double[,] t = new double[MatSize + 1, (MatSize + 1) * 2]; | ||
|
||
double det, detinv, ber, p; | ||
int n, i, j; | ||
|
||
n = MatSize; | ||
for (i = 1; i <= n; i++) | ||
{ | ||
for (j = 1; j <= n; j++) | ||
{ | ||
if (i == j) | ||
{ | ||
t[i,j] = 2.0001; | ||
t[i,n + 1 + j] = 1.0; | ||
} | ||
else | ||
{ | ||
t[i,j] = 1.0001; | ||
t[i,n + 1 + j] = 0.0; | ||
} | ||
} | ||
t[i,n + 1] = System.Math.Sqrt((float)i); | ||
} | ||
|
||
Inner(t, out det, ref n); | ||
|
||
for (i = 1; i <= n; i++) | ||
{ | ||
for (j = 1; j <= n; j++) | ||
{ | ||
p = t[i,j]; | ||
t[i,j] = t[i,n + 1 + j]; | ||
t[i,n + 1 + j] = p; | ||
} | ||
} | ||
|
||
Inner(t, out detinv, ref n); | ||
|
||
ber = 0.0; | ||
for (i = 1; i <= n; i++) | ||
{ | ||
ber = ber + System.Math.Abs(System.Math.Sqrt((double)i) - t[i,n + 1]); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static void Inner(double[,] t, out double det, ref int n) | ||
{ | ||
double tik, tkk; | ||
|
||
det = 1.0; | ||
for (int k = 1; k <= n; k++) | ||
{ | ||
tkk = t[k,k]; | ||
det = det * tkk; | ||
|
||
for (int j = 1; j <= (2 * n + 1); j++) | ||
{ | ||
t[k,j] = t[k,j] / tkk; | ||
} | ||
|
||
for (int i = 1; i <= n; i++) | ||
{ | ||
if (i != k) | ||
{ | ||
tik = t[i,k]; | ||
for (int j = 1; j <= (2 * n + 1); j++) | ||
{ | ||
t[i,j] = t[i,j] - t[k,j] * tik; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public static void Test() | ||
{ | ||
foreach (var iteration in Benchmark.Iterations) | ||
{ | ||
using (iteration.StartMeasurement()) | ||
{ | ||
Bench(); | ||
} | ||
} | ||
} | ||
|
||
private static bool TestBase() | ||
{ | ||
bool result = Bench(); | ||
return result; | ||
} | ||
|
||
public static int Main() | ||
{ | ||
bool result = TestBase(); | ||
return (result ? 100 : -1); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/tests/JIT/Performance/CodeQuality/Benchstones/MDBenchF/MDInvMt/MDInvMt.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> |
Oops, something went wrong.