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 BubbleSort2
19 public const int Iterations = 1;
20 public const int Bound = 5 * Iterations;
22 public const int Iterations = 15;
23 public const int Bound = 500 * Iterations;
26 static void Inner(int[] x) {
27 int limit1 = Bound - 1;
28 for (int i = 1; i <= limit1; i++) {
29 for (int j = i; j <= Bound; j++) {
39 [MethodImpl(MethodImplOptions.NoInlining)]
41 int[] x = new int[Bound + 1];
49 x[i + 1] = (j + 11111) & 32767;
50 x[i + 2] = (j + 22222) & 32767;
59 for (i = 0; i < Bound - 1; i++) {
60 if (x[i] > x[i + 1]) {
69 public static void Test() {
70 foreach (var iteration in Benchmark.Iterations) {
71 using (iteration.StartMeasurement()) {
72 for (int i = 0; i < Iterations; i++) {
79 static bool TestBase() {
81 for (int i = 0; i < Iterations; i++) {
87 public static int Main() {
88 bool result = TestBase();
89 return (result ? 100 : -1);