Update CoreClr, PgoData to preview1-26004-01, master-20171204-0047, respectively...
[platform/upstream/coreclr.git] / tests / src / JIT / Performance / CodeQuality / BenchF / BenchMrk / BenchMrk.cs
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.
4 //
5
6 using Microsoft.Xunit.Performance;
7 using System;
8 using System.Runtime.CompilerServices;
9 using Xunit;
10
11 [assembly: OptimizeForBenchmarks]
12
13 namespace Benchstone.BenchF
14 {
15 public static class BenchMrk
16 {
17 #if DEBUG
18     public const int Iterations = 1;
19 #else
20     public const int Iterations = 4000000;
21 #endif
22
23     private static int s_i, s_n;
24     private static float s_p, s_a, s_x, s_f, s_e;
25
26     [MethodImpl(MethodImplOptions.NoInlining)]
27     private static bool Bench()
28     {
29         s_p = (float)Math.Acos(-1.0);
30         s_a = 0.0F;
31         s_n = Iterations;
32         s_f = s_p / s_n;
33         for (s_i = 1; s_i <= s_n; ++s_i)
34         {
35             s_f = s_p / s_n;
36             s_x = s_f * s_i;
37             s_e = (float)(Math.Abs(Math.Log(Math.Exp(s_x)) / s_x) - Math.Sqrt((Math.Sin(s_x) * Math.Sin(s_x)) + Math.Cos(s_x) * Math.Cos(s_x)));
38             s_a = s_a + Math.Abs(s_e);
39         }
40
41         return true;
42     }
43
44     [Benchmark]
45     public static void Test()
46     {
47         foreach (var iteration in Benchmark.Iterations)
48         {
49             using (iteration.StartMeasurement())
50             {
51                 Bench();
52             }
53         }
54     }
55
56     private static bool TestBase()
57     {
58         bool result = Bench();
59         return result;
60     }
61
62     public static int Main()
63     {
64         bool result = TestBase();
65         return (result ? 100 : -1);
66     }
67 }
68 }