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 EightQueens
19 public const int Iterations = 1;
21 public const int Iterations = 100000;
24 static int[] m_c = new int[15];
25 static int[] m_x = new int[9];
27 static void TryMe(int i, ref int q, int[] a, int[] b)
31 while ((q == 0) && (j != 8)) {
34 if ((b[j] == 1) && (a[i + j] == 1) && (m_c[i - j + 7] == 1)) {
40 TryMe(i + 1, ref q, a, b);
54 [MethodImpl(MethodImplOptions.NoInlining)]
57 int[] b = new int[17];
61 if ((i >= 1) && (i <= 8)) {
73 TryMe(1, ref q, b, a);
79 public static void Test() {
80 foreach (var iteration in Benchmark.Iterations) {
81 using (iteration.StartMeasurement()) {
82 for (int i = 0; i < Iterations; i++) {
89 static bool TestBase() {
91 for (int i = 0; i < Iterations; i++) {
97 public static int Main() {
98 bool result = TestBase();
99 return (result ? 100 : -1);