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.BenchI
15 public static class XposMatrix
17 public const int ArraySize = 100;
20 public const int Iterations = 1;
22 public const int Iterations = 25000;
25 static T[][] AllocArray<T>(int n1, int n2) {
26 T[][] a = new T[n1][];
27 for (int i = 0; i < n1; ++i) {
33 static void Inner(int[][] x, int n) {
34 for (int i = 1; i <= n; i++) {
35 for (int j = 1; j <= n; j++) {
43 [MethodImpl(MethodImplOptions.NoInlining)]
44 static bool Bench(int[][] matrix) {
47 for (int i = 1; i <= n; i++) {
48 for (int j = 1; j <= n; j++) {
53 if (matrix[n][n] != 1) {
59 if (matrix[n][n] != 1) {
67 public static void Test() {
68 int[][] matrix = AllocArray<int>(ArraySize + 1, ArraySize + 1);
69 foreach (var iteration in Benchmark.Iterations) {
70 using (iteration.StartMeasurement()) {
71 for (int i = 0; i < Iterations; i++) {
78 static bool TestBase() {
79 int[][] matrix = AllocArray<int>(ArraySize + 1, ArraySize + 1);
81 for (int i = 0; i < Iterations; i++) {
82 result &= Bench(matrix);
87 public static int Main() {
88 bool result = TestBase();
89 return (result ? 100 : -1);