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 BubbleSort
19 public const int Iterations = 1;
21 public const int Iterations = 55000;
24 static void SortArray(int[] tab, int last) {
29 for (int i = 0; i < last; i++) {
30 if (tab[i] > tab[i + 1]) {
41 static bool VerifySort(int[] tab, int last) {
42 for (int i = 0; i < last; i++) {
43 if (tab[i] > tab[i + 1]) {
51 [MethodImpl(MethodImplOptions.NoInlining)]
52 static public bool Bench() {
53 int[] tab = new int[100];
55 for (int i = 9; i >= 0; i--) {
56 for (int j = i * 10; j < (i + 1) * 10; j++) {
57 tab[k++] = ((j & 1) == 1) ? j + 1 : j - 1;
61 bool result = VerifySort(tab, 99);
66 public static void Test() {
67 foreach (var iteration in Benchmark.Iterations) {
68 using (iteration.StartMeasurement()) {
69 for (int i = 0; i < Iterations; i++) {
76 static bool TestBase() {
78 for (int i = 0; i < Iterations; i++) {
84 public static int Main() {
85 bool result = TestBase();
86 return (result ? 100 : -1);