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.
5 // The Bisect algorithm adapted from Conte and de Boor
7 using Microsoft.Xunit.Performance;
9 using System.Runtime.CompilerServices;
12 [assembly: OptimizeForBenchmarks]
14 namespace Benchstone.BenchF
16 public static class Bisect
19 public const int Iterations = 1;
21 public const int Iterations = 400000;
24 public static volatile object VolatileObject;
26 [MethodImpl(MethodImplOptions.NoInlining)]
27 private static void Escape(object obj)
32 [MethodImpl(MethodImplOptions.NoInlining)]
33 private static bool Bench()
36 double a, b, error, p1, xi;
42 for (int i = 1; i <= Iterations; i++)
44 for (int j = 1; j <= 10; j++)
49 Inner(ref a, ref b, ref p1, out iflag);
58 error = (a - b) / 2.0;
62 error = (b - a) / 2.0;
67 System.Console.WriteLine(" the root is {0:E} plus/minus {1:E}\n", xi, error);
75 // Escape iflag, error, xi so that they appear live
83 private static double FF(double x)
85 return ((-1.0 - (x * (1.0 - (x * x)))));
88 private static void Inner(ref double a, ref double b, ref double xtol, out int iflag)
95 /* check for sign change */
96 if (((fa) * FF(b)) < 0.0)
106 error = System.Math.Abs(b - a);
110 /* check for sufficiently small interval */
116 /* check for unreasonable error requirement */
117 if (xm + error == xm)
123 /* change to new interval */
142 public static void Test()
144 foreach (var iteration in Benchmark.Iterations)
146 using (iteration.StartMeasurement())
153 private static bool TestBase()
155 bool result = Bench();
159 public static int Main()
161 bool result = TestBase();
162 return (result ? 100 : -1);