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 Ackermann
19 public const int Iterations = 1;
21 public const int Iterations = 100000;
24 static int Acker(int m, int n) {
29 return Acker(m - 1, 1);
32 return Acker(m - 1, Acker(m, n - 1));
36 [MethodImpl(MethodImplOptions.NoInlining)]
38 int a00 = Acker(0, 0);
39 int a11 = Acker(1, 1);
40 int a22 = Acker(2, 2);
41 int a33 = Acker(3, 3);
42 return (a00 == 1) && (a11 == 3) && (a22 == 7) & (a33 == 61);
46 public static void Test() {
47 foreach (var iteration in Benchmark.Iterations) {
48 using (iteration.StartMeasurement()) {
49 for (int i = 0; i < Iterations; i++) {
56 static bool TestBase() {
58 for (int i = 0; i < Iterations; i++) {
64 public static int Main() {
65 bool result = TestBase();
66 return (result ? 100 : -1);