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 class TreeInsert
18 public const int Iterations = 1;
20 public const int Iterations = 15000;
41 _s.Nodes = new Node[10001];
44 private void BenchInner(int x)
46 /* a tree insertion routine from knuth */
52 if (_s.Nodes[i].A < x)
54 if (_s.Nodes[i].L != 0)
67 if (_s.Nodes[i].R != 0)
88 [MethodImpl(MethodImplOptions.NoInlining)]
98 for (int i = 1; i <= 900; i++)
100 BenchInner(j & 4095);
104 return (_s.Nodes[500].A == 441);
108 public static void Test()
110 TreeInsert T = new TreeInsert();
111 foreach (var iteration in Benchmark.Iterations)
113 using (iteration.StartMeasurement())
115 for (int i = 1; i <= Iterations; i++)
123 private static bool TestBase()
125 TreeInsert T = new TreeInsert();
127 for (int i = 1; i <= Iterations; i++)
134 public static int Main()
136 bool result = TestBase();
137 return (result ? 100 : -1);