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.BenchF
15 public static class DMath
18 public const int Iterations = 1;
20 public const int Iterations = 100000;
23 private const double Deg2Rad = 57.29577951;
24 private static volatile object s_volatileObject;
26 private static void Escape(object obj)
28 s_volatileObject = obj;
31 private static double Fact(double n)
44 private static double Power(double n, double p)
57 [MethodImpl(MethodImplOptions.NoInlining)]
58 private static bool Bench(int loop)
60 double[] sines = new double[91];
61 double angle, radians, sine, worksine, temp, k;
64 for (int iter = 1; iter <= loop; iter++)
66 for (angle = 0.0; angle <= 90.0; angle += 1.0)
68 radians = angle / Deg2Rad;
74 temp = (2.0 * k) + 1.0;
75 worksine += (Power(-1.0, k) / Fact(temp)) * Power(radians, temp);
77 diff = Math.Abs(sine - worksine);
78 } while (diff > 1E-8);
80 sines[(int)angle] = worksine;
84 // Escape sines array so that its elements appear live-out
91 public static void Test()
93 foreach (var iteration in Benchmark.Iterations)
95 using (iteration.StartMeasurement())
102 private static bool TestBase()
104 bool result = Bench(Iterations);
108 public static int Main()
110 bool result = TestBase();
111 return (result ? 100 : -1);