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 class Permutate
18 public const int Iterations = 1;
20 public const int Iterations = 20000;
23 private int[] _permArray = new int[11];
24 private static int s_pctr;
27 void Swap(int[] arr, int i, int j)
34 private void Initialize()
36 for (int i = 1; i <= 7; i++)
38 _permArray[i] = i - 1;
42 private void PermuteArray(int n)
49 for (k = n - 1; k >= 1; k--)
51 Swap(_permArray, n, k);
53 Swap(_permArray, n, k);
58 private bool Validate()
62 for (int i = 0; i <= 6; i++)
64 for (int j = 1; j <= 7; j++)
66 if (_permArray[j] == i)
76 [MethodImpl(MethodImplOptions.NoInlining)]
81 for (int i = 0; i < Iterations; ++i)
87 bool result = Validate();
93 public static void Test()
95 Permutate P = new Permutate();
96 foreach (var iteration in Benchmark.Iterations)
98 using (iteration.StartMeasurement())
105 private static bool TestBase()
107 Permutate P = new Permutate();
108 bool result = P.Bench();
112 public static int Main()
114 bool result = TestBase();
115 return (result ? 100 : -1);