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 AddArray2
18 public const int Iterations = 1;
20 public const int Iterations = 50;
23 private const int Dim = 200;
25 private static T[][] AllocArray<T>(int n1, int n2)
27 T[][] a = new T[n1][];
28 for (int i = 0; i < n1; ++i)
36 void BenchInner1(int[][] a, ref int nn)
41 for (int i = 1; i <= n; i++)
43 for (int j = (i + 1); j <= n; j++)
45 for (int k = 1; k <= n; k++)
59 void BenchInner2(int[][] a, ref int nn)
64 for (int i = 1; i <= n; i++)
66 for (int j = (i + 1); j <= n; j++)
68 for (int k = 1; k <= n; k++)
81 [MethodImpl(MethodImplOptions.NoInlining)]
82 private static bool Bench(int[][] a)
85 for (int i = 1; i <= n; i++)
87 for (int j = 1; j <= n; j++)
93 BenchInner1(a, ref n);
95 BenchInner2(a, ref n);
101 public static void Test()
103 int[][] array = AllocArray<int>(Dim + 1, Dim + 1);
104 foreach (var iteration in Benchmark.Iterations)
106 using (iteration.StartMeasurement())
108 for (int i = 1; i <= Iterations; i++)
116 private static bool TestBase()
118 int[][] array = AllocArray<int>(Dim + 1, Dim + 1);
120 for (int i = 1; i <= Iterations; i++)
122 result &= Bench(array);
127 public static int Main()
129 bool result = TestBase();
130 return (result ? 100 : -1);