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 AddArray
19 public const int Iterations = 1;
21 public const int Iterations = 15000;
24 const int Size = 6000;
26 public static volatile object VolatileObject;
28 [MethodImpl(MethodImplOptions.NoInlining)]
29 static void Escape(object obj) {
33 [MethodImpl(MethodImplOptions.NoInlining)]
36 int[] flags1 = new int[Size + 1];
37 int[] flags2 = new int[Size + 1];
38 int[] flags3 = new int[Size + 1];
39 int[] flags4 = new int[Size + 1];
43 for (j = 0; j <= Size; j++) {
44 flags1[j] = 70000 + j;
46 flags2[k] = flags1[j] + k + k;
48 flags3[l] = flags2[k] + l + l + l;
50 flags4[m] = flags3[l] + m + m + m + m;
53 for (j = 0; j <= Size; j++) {
57 flags1[j] = flags1[j] + flags2[k] + flags3[l] + flags4[m] - flags2[k - j + l];
60 // Escape each flags array so that their elements will appear live-out
70 public static void Test() {
71 foreach (var iteration in Benchmark.Iterations) {
72 using (iteration.StartMeasurement()) {
73 for (int i = 0; i < Iterations; i++) {
80 static bool TestBase() {
82 for (int i = 0; i < Iterations; i++) {
88 public static int Main() {
89 bool result = TestBase();
90 return (result ? 100 : -1);