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 LogicArray
19 public const int Iterations = 1;
21 public const int Iterations = 3000;
24 const int ArraySize = 50;
32 static T[][] AllocArray<T>(int n1, int n2) {
33 T[][] a = new T[n1][];
34 for (int i = 0; i < n1; ++i) {
40 static bool Inner(ref Workarea cmn) {
43 for (i = 1; i <= 50; i++) {
44 for (j = 1; j <= 50; j++) {
48 for (k = 1; k <= 50; k++) {
49 for (j = 1; j <= 50; j++) {
52 cmn.X = cmn.X | cmn.A[i][j] & cmn.A[i + 1][k];
65 [MethodImpl(MethodImplOptions.NoInlining)]
67 Workarea cmn = new Workarea();
69 cmn.A = AllocArray<int>(51, 51);
70 for (int n = 1; n <= Iterations; n++) {
71 bool result = Inner(ref cmn);
81 public static void Test() {
82 foreach (var iteration in Benchmark.Iterations) {
83 using (iteration.StartMeasurement()) {
89 static bool TestBase() {
90 bool result = Bench();
94 public static int Main() {
95 bool result = TestBase();
96 return (result ? 100 : -1);