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 static class Pi
19 public const int Iterations = 1;
21 public const int Iterations = 100;
24 static int[] ComputePi(int[] a) {
29 int m = (int)(3.322 * n * d);
30 int[] digits = new int[n];
33 for (i = 0; i <= m; i++) {
39 for (i = 1; i <= n; i++) {
41 for (k = m; k > 0L; k--) {
43 q = a[k] / (2 * k + 1);
44 a[k] -= (2 * k + 1) * q;
56 [MethodImpl(MethodImplOptions.NoInlining)]
57 static bool Bench(int[] a) {
58 int[] digits = ComputePi(a);
59 return (digits[0] == 3 && digits[1] == 1415 && digits[2] == 9265 && digits[250] == 1989);
63 public static void Test() {
64 int[] a = new int[3340];
65 foreach (var iteration in Benchmark.Iterations) {
66 using (iteration.StartMeasurement()) {
67 for (int i = 0; i < Iterations; i++) {
74 static bool TestBase() {
76 int[] a = new int[3340];
77 for (int i = 0; i < Iterations; i++) {
83 public static int Main() {
84 bool result = TestBase();
85 return (result ? 100 : -1);