1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 using Microsoft.Xunit.Performance;
8 using System.Runtime.CompilerServices;
11 [assembly: OptimizeForBenchmarks]
13 namespace Benchstone.BenchF
15 public static class SqMtx
18 public const int Iterations = 1;
20 public const int Iterations = 4000;
23 private const int MatrixSize = 40;
25 private static T[][] AllocArray<T>(int n1, int n2)
27 T[][] a = new T[n1][];
28 for (int i = 0; i < n1; ++i)
35 [MethodImpl(MethodImplOptions.NoInlining)]
36 private static bool Bench()
38 double[][] a = AllocArray<double>(41, 41);
39 double[][] c = AllocArray<double>(41, 41);
43 for (i = 1; i <= MatrixSize; i++)
45 for (j = 1; j <= MatrixSize; j++)
51 for (i = 1; i <= Iterations; i++)
53 Inner(a, c, MatrixSize);
56 if (c[1][1] == 23820.0)
66 private static void Inner(double[][] a, double[][] c, int n)
68 for (int i = 1; i <= n; i++)
70 for (int j = 1; j <= n; j++)
73 for (int k = 1; k <= n; k++)
75 c[i][j] = c[i][j] + a[i][k] * a[k][j];
82 public static void Test()
84 foreach (var iteration in Benchmark.Iterations)
86 using (iteration.StartMeasurement())
93 private static bool TestBase()
95 bool result = Bench();
99 public static int Main()
101 bool result = TestBase();
102 return (result ? 100 : -1);