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 // Integration by Simpson's rule 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 Simpsn
19 public const int Iterations = 1;
21 public const int Iterations = 90000;
24 [MethodImpl(MethodImplOptions.NoInlining)]
25 private static bool Bench()
27 double a, b, x, s, c, h, hov2, half, t1;
34 System.Console.WriteLine("simpsons rule\n");
37 for (int j = 1; j <= Iterations; j++)
44 hov2 = h / System.Math.Sqrt(c);
49 for (int i = 1; i <= nm1; i++)
55 s = (h / 6) * (F(a) + 4 * half + 2 * s + F(b));
58 System.Console.WriteLine(" integral from a = {0} to b = {1} for n = {2} is {3}\n", a, b, n, s);
66 private static double F(double x)
68 return (System.Math.Exp((-(x)) * 2));
72 public static void Test()
74 foreach (var iteration in Benchmark.Iterations)
76 using (iteration.StartMeasurement())
83 private static bool TestBase()
85 bool result = Bench();
89 public static int Main()
91 bool result = TestBase();
92 return (result ? 100 : -1);