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 Array2
19 public const int Iterations = 1;
21 public const int Iterations = 500000;
24 static T[][][] AllocArray<T>(int n1, int n2, int n3) {
25 T[][][] a = new T[n1][][];
26 for (int i = 0; i < n1; ++i) {
28 for (int j = 0; j < n2; j++) {
36 static void Initialize(int[][][] s) {
37 for (int i = 0; i < 10; i++) {
38 for (int j = 0; j < 10; j++) {
39 for (int k = 0; k < 10; k++) {
40 s[i][j][k] = (2 * i) - (3 * j) + (5 * k);
46 static bool VerifyCopy(int[][][] s, int[][][] d) {
47 for (int i = 0; i < 10; i++) {
48 for (int j = 0; j < 10; j++) {
49 for (int k = 0; k < 10; k++) {
50 if (s[i][j][k] != d[i][j][k]) {
60 [MethodImpl(MethodImplOptions.NoInlining)]
61 static bool Bench(int loop) {
63 int[][][] s = AllocArray<int>(10, 10, 10);
64 int[][][] d = AllocArray<int>(10, 10, 10);
68 for (; loop != 0; loop--) {
69 for (int i = 0; i < 10; i++) {
70 for (int j = 0; j < 10; j++) {
71 for (int k = 0; k < 10; k++) {
72 d[i][j][k] = s[i][j][k];
78 bool result = VerifyCopy(s, d);
84 public static void Test() {
85 foreach (var iteration in Benchmark.Iterations) {
86 using (iteration.StartMeasurement()) {
92 static bool TestBase() {
93 bool result = Bench(Iterations);
97 public static int Main() {
98 bool result = TestBase();
99 return (result ? 100 : -1);