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 Midpoint
19 public const int Iterations = 1;
21 public const int Iterations = 70000;
24 static T[][] AllocArray<T>(int n1, int n2) {
25 T[][] a = new T[n1][];
26 for (int i = 0; i < n1; ++i) {
32 static int Inner(ref int x, ref int y, ref int z) {
65 [MethodImpl(MethodImplOptions.NoInlining)]
67 int[][] a = AllocArray<int>(2001, 4);
68 int[] mid = new int[2001];
71 for (int i = 1; i <= 2000; i++) {
73 a[i][2] = (j + 11111) & 32767;
74 a[i][3] = (j + 22222) & 32767;
78 for (int k = 1; k <= Iterations; k++) {
79 for (int l = 1; l <= 2000; l++) {
80 mid[l] = Inner(ref a[l][1], ref a[l][2], ref a[l][3]);
84 return (mid[2000] == 17018);
88 public static void Test() {
89 foreach (var iteration in Benchmark.Iterations) {
90 using (iteration.StartMeasurement()) {
96 static bool TestBase() {
97 bool result = Bench();
101 public static int Main() {
102 bool result = TestBase();
103 return (result ? 100 : -1);