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 corrected trapezoid 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 Trap
19 public const int Iterations = 1;
21 public const int Iterations = 240000;
24 [MethodImpl(MethodImplOptions.NoInlining)]
25 private static bool Bench()
28 double t2, cortrp, trap, a, b, h;
33 for (int j = 1; j <= Iterations; j++)
39 System.Console.WriteLine("trapazoid sum corr.trap sum \n");
42 for (int n = 10; n <= 15; n++)
46 trap = (F(a) + F(b)) / 2;
47 for (int i = 1; i <= nm1; i++)
53 cortrp = trap + h * h * (FPrime(a) - FPrime(b)) / 12;
56 System.Console.WriteLine("{0}, {1}, {2}\n", n, trap, cortrp);
64 private static double F(double x)
66 return (System.Math.Exp(-(x) * (x)));
69 private static double FPrime(double x)
71 return ((-2) * (x) * (F(x)));
75 public static void Test()
77 foreach (var iteration in Benchmark.Iterations)
79 using (iteration.StartMeasurement())
86 private static bool TestBase()
88 bool result = Bench();
92 public static int Main()
94 bool result = TestBase();
95 return (result ? 100 : -1);