Add 15 more Benchstone floating-point (BenchF) benchmarks in Xunit format.
authorChris McKinsey <chrismck@microsoft.com>
Mon, 1 Feb 2016 19:35:32 +0000 (11:35 -0800)
committerChris McKinsey <chrismck@microsoft.com>
Mon, 1 Feb 2016 20:52:40 +0000 (12:52 -0800)
Update all BenchF sources with CodeFormatter tool.

35 files changed:
tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/BenchMk2/BenchMk2.cs
tests/src/JIT/Performance/CodeQuality/BenchF/BenchMrk/BenchMrk.cs
tests/src/JIT/Performance/CodeQuality/BenchF/Bisect/Bisect.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Bisect/Bisect.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.cs
tests/src/JIT/Performance/CodeQuality/BenchF/FFT/FFT.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/FFT/FFT.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/InProd/InProd.cs
tests/src/JIT/Performance/CodeQuality/BenchF/InvMt/InvMt.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/InvMt/InvMt.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/LLoops/LLoops.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/LLoops/LLoops.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Lorenz/Lorenz.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Lorenz/Lorenz.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/MatInv4/MatInv4.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/MatInv4/MatInv4.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/NewtR/NewtR.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/NewtR/NewtR.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Regula/Regula.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Regula/Regula.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Romber/Romber.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Romber/Romber.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Secant/Secant.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Secant/Secant.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Simpsn/Simpsn.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Simpsn/Simpsn.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/SqMtx/SqMtx.cs
tests/src/JIT/Performance/CodeQuality/BenchF/Trap/Trap.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Trap/Trap.csproj [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Whetsto/Whetsto.cs [new file with mode: 0644]
tests/src/JIT/Performance/CodeQuality/BenchF/Whetsto/Whetsto.csproj [new file with mode: 0644]

diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.cs
new file mode 100644 (file)
index 0000000..0edc8b9
--- /dev/null
@@ -0,0 +1,106 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// The Adams-Moulton Predictor Corrector Method adapted from Conte and de Boor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Adams
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 200000;
+#endif
+
+    public static volatile object VolatileObject;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static void Escape(object obj)
+    {
+        VolatileObject = obj;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double[] f = new double[5];
+        double xn, yn, h, fnp, ynp, y0, x0;
+        int i, k, l, n, nstep;
+
+        n = 4;
+        h = 1.0 / 32.0;
+        nstep = 32;
+        y0 = 0.0;
+        x0 = 0.0;
+        xn = 0.0;
+        yn = 0.0;
+
+        for (l = 1; l <= Iterations; l++)
+        {
+            f[1] = x0 + y0;
+
+            xn = x0;
+            for (i = 2; i <= 4; i++)
+            {
+                k = i - 1;
+                xn = xn + h;
+                yn = Soln(xn);
+                f[i] = xn + yn;
+            }
+
+            for (k = 4; k <= nstep; k++)
+            {
+                ynp = yn + (h / 24) * (55 * f[n] - 59 * f[n - 1] + 37 * f[n - 2] - 9 * f[n - 3]);
+                xn = xn + h;
+                fnp = xn + ynp;
+                yn = yn + (h / 24) * (9 * fnp + 19 * f[n] - 5 * f[n - 1] + f[n - 2]);
+                f[n - 3] = f[n - 2];
+                f[n - 2] = f[n - 1];
+                f[n - 1] = f[n];
+                f[n] = xn + yn;
+            }
+        }
+
+        // Escape f so that its elements will be live-out
+        Escape(f);
+
+        return true;
+    }
+
+    private static double Soln(double x)
+    {
+        return (System.Math.Exp(x) - 1.0 - (x));
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Adams/Adams.csproj
new file mode 100644 (file)
index 0000000..d763140
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Adams.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
index a53545f..9701644 100644 (file)
@@ -13,47 +13,53 @@ using Xunit;
 
 public static class BenchMk2
 {
-
 #if DEBUG
     public const int Iterations = 1;
 #else
     public const int Iterations = 4000000;
 #endif
 
-    static int s_i, s_n;
-    static double s_p, s_a, s_x, s_f, s_e;
+    private static int s_i, s_n;
+    private static double s_p, s_a, s_x, s_f, s_e;
 
     [MethodImpl(MethodImplOptions.NoInlining)]
-    static bool Bench() {
-       s_p = Math.Acos(-1.0);
-       s_a = 0.0;
-       s_n = Iterations;
-       s_f = s_p / s_n;
-       for (s_i = 1; s_i <= s_n; ++s_i) {
-          s_f = s_p / s_n;
-          s_x = s_f * s_i;
-          s_e = 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));
-          s_a = s_a + Math.Abs(s_e);
-       }
-
-       return true;
+    private static bool Bench()
+    {
+        s_p = Math.Acos(-1.0);
+        s_a = 0.0;
+        s_n = Iterations;
+        s_f = s_p / s_n;
+        for (s_i = 1; s_i <= s_n; ++s_i)
+        {
+            s_f = s_p / s_n;
+            s_x = s_f * s_i;
+            s_e = 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));
+            s_a = s_a + Math.Abs(s_e);
+        }
+
+        return true;
     }
 
     [Benchmark]
-    public static void Test() {
-        foreach (var iteration in Benchmark.Iterations) {
-            using (iteration.StartMeasurement()) {
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
                 Bench();
             }
         }
     }
 
-    static bool TestBase() {
+    private static bool TestBase()
+    {
         bool result = Bench();
         return result;
     }
 
-    public static int Main() {
+    public static int Main()
+    {
         bool result = TestBase();
         return (result ? 100 : -1);
     }
index 2de904b..27a5fe6 100644 (file)
@@ -13,23 +13,24 @@ using Xunit;
 
 public static class BenchMrk
 {
-
 #if DEBUG
     public const int Iterations = 1;
 #else
     public const int Iterations = 4000000;
 #endif
 
-    static int s_i, s_n;
-    static float s_p, s_a, s_x, s_f, s_e;
+    private static int s_i, s_n;
+    private static float s_p, s_a, s_x, s_f, s_e;
 
     [MethodImpl(MethodImplOptions.NoInlining)]
-    static bool Bench() {
+    private static bool Bench()
+    {
         s_p = (float)Math.Acos(-1.0);
         s_a = 0.0F;
         s_n = Iterations;
         s_f = s_p / s_n;
-        for (s_i = 1; s_i <= s_n; ++s_i) {
+        for (s_i = 1; s_i <= s_n; ++s_i)
+        {
             s_f = s_p / s_n;
             s_x = s_f * s_i;
             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)));
@@ -40,20 +41,25 @@ public static class BenchMrk
     }
 
     [Benchmark]
-    public static void Test() {
-        foreach (var iteration in Benchmark.Iterations) {
-            using (iteration.StartMeasurement()) {
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
                 Bench();
             }
         }
     }
 
-    static bool TestBase() {
+    private static bool TestBase()
+    {
         bool result = Bench();
         return result;
     }
 
-    public static int Main() {
+    public static int Main()
+    {
         bool result = TestBase();
         return (result ? 100 : -1);
     }
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Bisect/Bisect.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Bisect/Bisect.cs
new file mode 100644 (file)
index 0000000..1c27003
--- /dev/null
@@ -0,0 +1,163 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// The Bisect algorithm adapted from Conte and de Boor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Bisect
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 400000;
+#endif
+
+    public static volatile object VolatileObject;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static void Escape(object obj)
+    {
+        VolatileObject = obj;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        int idbg, iflag;
+        double a, b, error, p1, xi;
+
+        iflag = 0;
+        error = 0.0;
+        xi = 0.0;
+        idbg = 0;
+        for (int i = 1; i <= Iterations; i++)
+        {
+            for (int j = 1; j <= 10; j++)
+            {
+                a = 1.0;
+                b = 2.0;
+                p1 = 0.000001;
+                Inner(ref a, ref b, ref p1, out iflag);
+                if (iflag > 1)
+                {
+                    goto L999;
+                }
+
+                xi = (a + b) / 2.0;
+                if (a > b)
+                {
+                    error = (a - b) / 2.0;
+                }
+                else
+                {
+                    error = (b - a) / 2.0;
+                }
+
+                if (idbg != 0)
+                {
+                    System.Console.WriteLine(" the root is {0:E} plus/minus {1:E}\n", xi, error);
+                }
+            }
+        }
+    L999:
+        {
+        }
+
+        // Escape iflag, error, xi so that they appear live
+        Escape(iflag);
+        Escape(error);
+        Escape(xi);
+
+        return true;
+    }
+
+    private static double FF(double x)
+    {
+        return ((-1.0 - (x * (1.0 - (x * x)))));
+    }
+
+    private static void Inner(ref double a, ref double b, ref double xtol, out int iflag)
+    {
+        double fa, error;
+        double xm, fm;
+
+        iflag = 0;
+        fa = FF(a);
+        /*      check for sign change  */
+        if (((fa) * FF(b)) < 0.0)
+        {
+            goto L5;
+        }
+
+        iflag = 2;
+        goto L99;
+
+    L5:
+        {
+            error = System.Math.Abs(b - a);
+        }
+    L6:
+        error = error / 2.0;
+        /*      check for sufficiently small interval  */
+        if (error < xtol)
+        {
+            goto L99;
+        }
+        xm = (a + b) / 2.0;
+        /*      check for unreasonable error requirement */
+        if (xm + error == xm)
+        {
+            goto L20;
+        }
+
+        fm = FF(xm);
+        /*      change to new interval  */
+        if (fa * fm < 0.0)
+        {
+            goto L9;
+        }
+        a = xm;
+        fa = fm;
+        goto L6;
+    L9:
+        b = xm;
+        goto L6;
+    L20:
+        iflag = 1;
+    L99:
+        {
+        }
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Bisect/Bisect.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Bisect/Bisect.csproj
new file mode 100644 (file)
index 0000000..d19aa33
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Bisect.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
index 82216b0..a2c3a38 100644 (file)
@@ -13,89 +13,99 @@ using Xunit;
 
 public static class DMath
 {
-
 #if DEBUG
     public const int Iterations = 1;
 #else
     public const int Iterations = 100000;
 #endif
 
-    const double Deg2Rad = 57.29577951;
-    static volatile object VolatileObject;
+    private const double Deg2Rad = 57.29577951;
+    private static volatile object s_volatileObject;
 
-    static void Escape(object obj) {
-        VolatileObject = obj;
+    private static void Escape(object obj)
+    {
+        s_volatileObject = obj;
     }
 
-    static double Fact(double n)
+    private static double Fact(double n)
     {
-       double res;
-       res = 1.0;
-       while (n > 0.0) {
-          res *= n;
-          n -= 1.0;
-       }
-
-       return res;
+        double res;
+        res = 1.0;
+        while (n > 0.0)
+        {
+            res *= n;
+            n -= 1.0;
+        }
+
+        return res;
     }
 
-    static double Power(double n, double p)
+    private static double Power(double n, double p)
     {
-       double res;
-       res = 1.0;
-       while (p > 0.0) {
-          res *= n;
-          p -= 1.0;
-       }
-
-       return res;
+        double res;
+        res = 1.0;
+        while (p > 0.0)
+        {
+            res *= n;
+            p -= 1.0;
+        }
+
+        return res;
     }
 
     [MethodImpl(MethodImplOptions.NoInlining)]
-    static bool Bench(int loop)
+    private static bool Bench(int loop)
     {
-       double[] sines = new double[91];
-       double angle, radians, sine, worksine, temp, k;
-       double diff;
-
-       for (int iter = 1; iter <= loop; iter++) {
-           for (angle = 0.0; angle <= 90.0; angle += 1.0) {
-               radians = angle / Deg2Rad;
-               k = 0.0;
-               worksine = 0.0;
-               do {
-                   sine = worksine;
-                   temp = (2.0 * k) + 1.0;
-                   worksine += (Power(-1.0, k) / Fact(temp)) * Power(radians, temp);
-                   k += 1.0;
-                   diff = Math.Abs(sine - worksine);
-               } while (diff > 1E-8);
-
-               sines[(int)angle] = worksine;
-           }
-       }
-
-       // Escape sines array so that its elements appear live-out
-       Escape(sines);
-
-       return true;
+        double[] sines = new double[91];
+        double angle, radians, sine, worksine, temp, k;
+        double diff;
+
+        for (int iter = 1; iter <= loop; iter++)
+        {
+            for (angle = 0.0; angle <= 90.0; angle += 1.0)
+            {
+                radians = angle / Deg2Rad;
+                k = 0.0;
+                worksine = 0.0;
+                do
+                {
+                    sine = worksine;
+                    temp = (2.0 * k) + 1.0;
+                    worksine += (Power(-1.0, k) / Fact(temp)) * Power(radians, temp);
+                    k += 1.0;
+                    diff = Math.Abs(sine - worksine);
+                } while (diff > 1E-8);
+
+                sines[(int)angle] = worksine;
+            }
+        }
+
+        // Escape sines array so that its elements appear live-out
+        Escape(sines);
+
+        return true;
     }
 
     [Benchmark]
-    public static void Test() {
-        foreach (var iteration in Benchmark.Iterations) {
-            using (iteration.StartMeasurement()) {
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
                 Bench(Iterations);
             }
         }
     }
 
-    static bool TestBase() {
+    private static bool TestBase()
+    {
         bool result = Bench(Iterations);
         return result;
     }
 
-    public static int Main() {
+    public static int Main()
+    {
         bool result = TestBase();
         return (result ? 100 : -1);
     }
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/FFT/FFT.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/FFT/FFT.cs
new file mode 100644 (file)
index 0000000..3e85327
--- /dev/null
@@ -0,0 +1,153 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// FFT benchmark adapted from a Fortran routine from the book
+// Digital Signal Analysis, Samuel Stearns, Hayden Book Co.
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class FFT
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 300000;
+#endif
+
+    private static readonly int s_points = 16;
+    public static volatile object VolatileObject;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static void Escape(object obj)
+    {
+        VolatileObject = obj;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double[] fr = new double[17];
+        double[] fi = new double[17];
+
+        int i;
+        double t;
+
+        for (int iter = 1; iter <= Iterations; iter++)
+        {
+            for (i = 1; i <= s_points; ++i)
+            {
+                t = ((double)0.375) * ((double)(i - 1));
+                fr[i] = System.Math.Exp(-t) * System.Math.Sin(t);
+                fi[i] = 0.0;
+            }
+            FastFourierT(fr, fi, s_points);
+        }
+
+        // Escape the results to live-out.
+        Escape(fr);
+        Escape(fi);
+
+        return true;
+    }
+
+    private static void FastFourierT(double[] fr, double[] fi, int n)
+    {
+        int i, j, l, m;
+        int istep, mr, nn;
+        double a, el, tr, ti, wr, wi;
+
+        mr = 0;
+        nn = n - 1;
+        m = 1;
+
+        do
+        {
+            l = n;
+            for (l = l / 2; ((mr + l) > nn); l = l / 2)
+            {
+            }
+            // l <= n/2
+            // mr <= (mr % l) + l ==> mr <= (l - 1) + l = 2l - 1
+            // ==> mr <= n - 1
+            mr = (mr % l) + l;
+
+            if (mr > m)
+            {
+                // Accessing upto m + 1 ==> nn + 1 ==> n - 1 + 1 ==> n
+                tr = fr[m + 1];
+                // Accessing upto mr + 1 ==> n - 1 + 1 ==> n
+                fr[m + 1] = fr[mr + 1];
+                fr[mr + 1] = tr;
+                ti = fi[m + 1];
+                fi[m + 1] = fi[mr + 1];
+                fi[mr + 1] = ti;
+            }
+            ++m;
+        } while (m <= nn);
+
+        for (l = 1; l < n; l = istep)
+        {
+            istep = 2 * l;
+
+            el = ((double)l);
+            m = 1;
+            do
+            {
+                a = ((double)3.1415926535) * (((double)(1 - m)) / el);
+                wr = System.Math.Cos(a);
+                wi = System.Math.Sin(a);
+                i = m;
+                do
+                {
+                    // l can have a maximum value of 2^x where 2^x < n and 2^(x+1) = n, since n is even
+                    // ==> istep <= 2^(x+1) ==> i can only take the value of m and m <= l
+                    // Therefore, j <= l + l
+                    // or j <= 2^x + 2^x = 2^(x+1) = n
+                    // i.e. j <= n
+                    j = i + l;
+
+                    // Accessing upto j <= n, i <= n
+                    tr = wr * fr[j] - wi * fi[j];
+                    ti = wr * fi[j] + wi * fr[j];
+                    fr[j] = fr[i] - tr;
+                    fi[j] = fi[i] - ti;
+                    fr[i] = fr[i] + tr;
+                    fi[i] = fi[i] + ti;
+                    i += istep;
+                } while (i <= n);
+                ++m;
+            } while (m <= l);
+        }
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/FFT/FFT.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/FFT/FFT.csproj
new file mode 100644 (file)
index 0000000..b447e50
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="FFT.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
index 7c962dd..ff54ea7 100644 (file)
@@ -13,27 +13,29 @@ using Xunit;
 
 public static class InProd
 {
-
 #if DEBUG
     public const int Iterations = 1;
 #else
     public const int Iterations = 70;
 #endif
 
-    const int RowSize = 10 * Iterations;
+    private const int RowSize = 10 * Iterations;
 
-    static int s_seed;
+    private static int s_seed;
 
-    static T[][] AllocArray<T>(int n1, int n2) {
+    private static T[][] AllocArray<T>(int n1, int n2)
+    {
         T[][] a = new T[n1][];
-        for (int i = 0; i < n1; ++i) {
+        for (int i = 0; i < n1; ++i)
+        {
             a[i] = new T[n2];
         }
         return a;
     }
 
     [MethodImpl(MethodImplOptions.NoInlining)]
-    static bool Bench() {
+    private static bool Bench()
+    {
         double[][] rma = AllocArray<double>(RowSize, RowSize);
         double[][] rmb = AllocArray<double>(RowSize, RowSize);
         double[][] rmr = AllocArray<double>(RowSize, RowSize);
@@ -55,23 +57,25 @@ public static class InProd
                 {
                     return false;
                 }
-           }
+            }
         }
 
         return true;
     }
 
-    static void InitRand()
+    private static void InitRand()
     {
         s_seed = 7774755;
     }
 
-    static int Rand() {
+    private static int Rand()
+    {
         s_seed = (s_seed * 77 + 13218009) % 3687091;
         return s_seed;
     }
 
-    static void InitMatrix(double[][] m) {
+    private static void InitMatrix(double[][] m)
+    {
         for (int i = 1; i < RowSize; i++)
         {
             for (int j = 1; j < RowSize; j++)
@@ -81,7 +85,8 @@ public static class InProd
         }
     }
 
-    static void InnerProduct(out double result, double[][] a, double[][] b, int row, int col) {
+    private static void InnerProduct(out double result, double[][] a, double[][] b, int row, int col)
+    {
         result = 0.0;
         for (int i = 1; i < RowSize; i++)
         {
@@ -89,7 +94,8 @@ public static class InProd
         }
     }
 
-    static void Inner(double[][] rma, double[][] rmb, double[][] rmr) {
+    private static void Inner(double[][] rma, double[][] rmb, double[][] rmr)
+    {
         InitRand();
         InitMatrix(rma);
         InitMatrix(rmb);
@@ -103,20 +109,25 @@ public static class InProd
     }
 
     [Benchmark]
-    public static void Test() {
-        foreach (var iteration in Benchmark.Iterations) {
-            using (iteration.StartMeasurement()) {
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
                 Bench();
             }
         }
     }
 
-    static bool TestBase() {
+    private static bool TestBase()
+    {
         bool result = Bench();
         return result;
     }
 
-    public static int Main() {
+    public static int Main()
+    {
         bool result = TestBase();
         return (result ? 100 : -1);
     }
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/InvMt/InvMt.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/InvMt/InvMt.cs
new file mode 100644 (file)
index 0000000..a5f387b
--- /dev/null
@@ -0,0 +1,137 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// Solution of linear algebraic equations and matrix inversion.
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class InvMt
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 80;
+#endif
+
+    private const int MatSize = Iterations;
+
+    private static T[][] AllocArray<T>(int n1, int n2)
+    {
+        T[][] a = new T[n1][];
+        for (int i = 0; i < n1; ++i)
+        {
+            a[i] = new T[n2];
+        }
+        return a;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double[][] t = AllocArray<double>(MatSize + 1, (MatSize + 1) * 2);
+
+        double det, detinv, ber, p;
+        int n, i, j;
+
+        n = MatSize;
+        for (i = 1; i <= n; i++)
+        {
+            for (j = 1; j <= n; j++)
+            {
+                if (i == j)
+                {
+                    t[i][j] = 2.0001;
+                    t[i][n + 1 + j] = 1.0;
+                }
+                else
+                {
+                    t[i][j] = 1.0001;
+                    t[i][n + 1 + j] = 0.0;
+                }
+            }
+            t[i][n + 1] = System.Math.Sqrt((float)i);
+        }
+
+        Inner(t, out det, ref n);
+
+        for (i = 1; i <= n; i++)
+        {
+            for (j = 1; j <= n; j++)
+            {
+                p = t[i][j];
+                t[i][j] = t[i][n + 1 + j];
+                t[i][n + 1 + j] = p;
+            }
+        }
+
+        Inner(t, out detinv, ref n);
+
+        ber = 0.0;
+        for (i = 1; i <= n; i++)
+        {
+            ber = ber + System.Math.Abs(System.Math.Sqrt((double)i) - t[i][n + 1]);
+        }
+
+        return true;
+    }
+
+    private static void Inner(double[][] t, out double det, ref int n)
+    {
+        double tik, tkk;
+
+        det = 1.0;
+        for (int k = 1; k <= n; k++)
+        {
+            tkk = t[k][k];
+            det = det * tkk;
+
+            for (int j = 1; j <= (2 * n + 1); j++)
+            {
+                t[k][j] = t[k][j] / tkk;
+            }
+
+            for (int i = 1; i <= n; i++)
+            {
+                if (i != k)
+                {
+                    tik = t[i][k];
+                    for (int j = 1; j <= (2 * n + 1); j++)
+                    {
+                        t[i][j] = t[i][j] - t[k][j] * tik;
+                    }
+                }
+            }
+        }
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/InvMt/InvMt.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/InvMt/InvMt.csproj
new file mode 100644 (file)
index 0000000..577bbdc
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="InvMt.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/LLoops/LLoops.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/LLoops/LLoops.cs
new file mode 100644 (file)
index 0000000..6dcb6c4
--- /dev/null
@@ -0,0 +1,650 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// C# adaptation of C implementation of Livermore Loops Fortran benchmark.
+
+/* Livermore Loops coded in C        Latest File Modification  20 Oct 92,
+ *  by Tim Peters, Kendall Square Res. Corp. tim@ksr.com, ksr!tim@uunet.uu.net
+ *     SUBROUTINE KERNEL( TK)  replaces the Fortran routine in LFK Test program.
+ ************************************************************************
+ *                                                                      *
+ *            KERNEL     executes 24 samples of "C" computation         *
+ *                                                                      *
+ *                TK(1) - total cpu time to execute only the 24 kernels.*
+ *                TK(2) - total Flops executed by the 24 Kernels        *
+ *                                                                      *
+ ************************************************************************
+ *                                                                      *
+ *     L. L. N. L.   " C "   K E R N E L S:   M F L O P S               *
+ *                                                                      *
+ *     These kernels measure   " C "   numerical computation            *
+ *     rates for  a  spectrum  of  cpu-limited computational            *
+ *     structures or benchmarks.   Mathematical  through-put            *
+ *     is measured  in  units  of millions of floating-point            *
+ *     operations executed per second, called Megaflops/sec.            *
+ *                                                                      *
+ *     Fonzi's Law: There is not now and there never will be a language *
+ *                  in which it is the least bit difficult to write     *
+ *                  bad programs.                                       *
+ *                                                    F.H.MCMAHON  1972 *
+ ************************************************************************
+ *Originally from  Greg Astfalk, AT&T, P.O.Box 900, Princeton, NJ. 08540*
+ *               by way of Frank McMahon (LLNL).                        *
+ *                                                                      *
+ *                               REFERENCE                              *
+ *                                                                      *
+ *              F.H.McMahon,   The Livermore Fortran Kernels:           *
+ *              A Computer Test Of The Numerical Performance Range,     *
+ *              Lawrence Livermore National Laboratory,                 *
+ *              Livermore, California, UCRL-53745, December 1986.       *
+ *                                                                      *
+ *       from:  National Technical Information Service                  *
+ *              U.S. Department of Commerce                             *
+ *              5285 Port Royal Road                                    *
+ *              Springfield, VA.  22161                                 *
+ *                                                                      *
+ *    Changes made to correct many array subscripting problems,         *
+ *      make more readable (added #define's), include the original      *
+ *      FORTRAN versions of the runs as comments, and make more         *
+ *      portable by Kelly O'Hair (LLNL) and Chuck Rasbold (LLNL).       *
+ *                                                                      *
+ ************************************************************************
+ */
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public class LLoops
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 4000;
+#endif
+
+    private const double MaxErr = 1.0e-6;
+
+    private double[] _x = new double[1002];
+    private double[] _y = new double[1002];
+    private double[] _z = new double[1002];
+    private double[] _u = new double[501];
+    private double[][] _px;
+    private double[][] _cx;
+    private double[][][] _u1;
+    private double[][][] _u2;
+    private double[][][] _u3;
+    private double[][] _b;
+    private double[] _bnk1 = new double[6];
+    private double[][] _c;
+    private double[] _bnk2 = new double[6];
+    private double[][] _p;
+    private double[] _bnk3 = new double[6];
+    private double[][] _h;
+    private double[] _bnk4 = new double[6];
+    private double[] _bnk5 = new double[6];
+    private double[] _ex = new double[68];
+    private double[] _rh = new double[68];
+    private double[] _dex = new double[68];
+    private double[] _vx = new double[151];
+    private double[] _xx = new double[151];
+    private double[] _grd = new double[151];
+    private int[] _e = new int[193];
+    private int[] _f = new int[193];
+    private int[] _nrops = { 0, 5, 10, 2, 2, 2, 2, 16, 36, 17, 9, 1, 1, 7, 11 };
+    private int[] _loops = { 0, 400, 200, 1000, 510, 1000, 1000, 120, 40, 100, 100, 1000, 1000, 128, 150 };
+    private double[] _checks = {
+        0, 0.811986948148e+07, 0.356310000000e+03, 0.356310000000e+03, -0.402412007078e+05,
+        0.136579037764e+06, 0.419716278716e+06,
+        0.429449847526e+07, 0.314064400000e+06,
+        0.182709000000e+07, -0.140415250000e+09,
+        0.374895020500e+09, 0.000000000000e+00,
+        0.171449024000e+06, -0.510829560800e+07
+    };
+
+    public static volatile object VolatileObject;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static void Escape(object obj)
+    {
+        VolatileObject = obj;
+    }
+
+    private static T[][] AllocArray<T>(int n1, int n2)
+    {
+        T[][] a = new T[n1][];
+        for (int i = 0; i < n1; ++i)
+        {
+            a[i] = new T[n2];
+        }
+        return a;
+    }
+
+    private static T[][][] AllocArray<T>(int n1, int n2, int n3)
+    {
+        T[][][] a = new T[n1][][];
+        for (int i = 0; i < n1; ++i)
+        {
+            a[i] = new T[n2][];
+            for (int j = 0; j < n2; j++)
+            {
+                a[i][j] = new T[n3];
+            }
+        }
+
+        return a;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private bool Bench()
+    {
+        _px = AllocArray<double>(16, 101);
+        _cx = AllocArray<double>(16, 101);
+
+        _u1 = AllocArray<double>(6, 23, 3);
+        _u2 = AllocArray<double>(6, 23, 3);
+        _u3 = AllocArray<double>(6, 23, 3);
+
+        _b = AllocArray<double>(65, 9);
+        _c = AllocArray<double>(65, 9);
+        _h = AllocArray<double>(65, 9);
+
+        _p = AllocArray<double>(5, 513);
+
+        for (int i = 0; i < Iterations; i++)
+        {
+            Main1(i < Iterations - 1 ? 0 : 1);
+        }
+
+        return true;
+    }
+
+    private static int Clock()
+    {
+        return 0;
+    }
+
+    private void Main1(int output)
+    {
+        int nt, lw, nl1, nl2;
+        int i, i1, i2, ip, ir, ix, j, j1, j2, k, kx, ky, l, m;
+        double[] ts = new double[21];
+        double[] rt = new double[21];
+        double[] rpm = new double[21];
+        double[] cksum = new double[21];
+        double r, t, a11, a12, a13, sig, a21, a22, a23, a31, a32, a33;
+        double b28, b27, b26, b25, b24, b23, b22, c0, flx, rx1;
+        double q, s, scale, uu, du1, du2, du3, ar, br, cr, xi, ri;
+        int[] mops = new int[20];
+
+        for (i = 1; i <= 20; i++)
+        {
+            cksum[i] = 0.0;
+        }
+
+        r = 4.86;
+        t = 276.0;
+        a11 = 0.5;
+        a12 = 0.33;
+        a13 = 0.25;
+        sig = 0.8;
+        a21 = 0.20;
+        a22 = 0.167;
+        a23 = 0.141;
+        a31 = 0.125;
+        a32 = 0.111;
+        a33 = 0.10;
+        b28 = 0.1;
+        b27 = 0.2;
+        b26 = 0.3;
+        b25 = 0.4;
+        b24 = 0.5;
+        b23 = 0.6;
+        b22 = 0.7;
+        c0 = 0.8;
+        flx = 4.689;
+        rx1 = 64.0;
+
+        /*
+         *     end of initialization -- begin timing
+         */
+
+        /* loop 1      hydro excerpt */
+
+        Init();
+        ts[1] = (double)Clock();
+        q = 0.0;
+        for (k = 1; k <= 400; k++)
+        {
+            _x[k] = q + _y[k] * (r * _z[k + 10] + t * _z[k + 11]);
+        }
+        ts[1] = (double)Clock() - ts[1];
+        for (k = 1; k <= 400; k++)
+        {
+            cksum[1] += (double)k * _x[k];
+        }
+
+        /* loop 2      mlr, inner product */
+
+        Init();
+        ts[2] = (double)Clock();
+        q = 0.0;
+        for (k = 1; k <= 996; k += 5)
+        {
+            q += _z[k] * _x[k] + _z[k + 1] * _x[k + 1] + _z[k + 2] * _x[k + 2] + _z[k + 3] * _x[k + 3] + _z[k + 4] * _x[k + 4];
+        }
+        ts[2] = (double)Clock() - ts[2];
+        cksum[2] = q;
+
+        /* loop 3      inner prod */
+
+        Init();
+        ts[3] = (double)Clock();
+        q = 0.0;
+        for (k = 1; k <= 1000; k++)
+        {
+            q += _z[k] * _x[k];
+        }
+        ts[3] = (double)Clock() - ts[3];
+        cksum[3] = q;
+
+        /* loop 4      banded linear equarions */
+
+        Init();
+        ts[4] = (double)Clock();
+        for (l = 7; l <= 107; l += 50)
+        {
+            lw = l;
+            for (j = 30; j <= 870; j += 5)
+            {
+                _x[l - 1] -= _x[lw++] * _y[j];
+            }
+            _x[l - 1] = _y[5] * _x[l - 1];
+        }
+        ts[4] = (double)Clock() - ts[4];
+        for (l = 7; l <= 107; l += 50)
+        {
+            cksum[4] += (double)l * _x[l - 1];
+        }
+
+        /* loop 5      tri-diagonal elimination, below diagonal */
+
+        Init();
+        ts[5] = (double)Clock();
+        for (i = 2; i <= 998; i += 3)
+        {
+            _x[i] = _z[i] * (_y[i] - _x[i - 1]);
+            _x[i + 1] = _z[i + 1] * (_y[i + 1] - _x[i]);
+            _x[i + 2] = _z[i + 2] * (_y[i + 2] - _x[i + 1]);
+        }
+        ts[5] = (double)Clock() - ts[5];
+        for (i = 2; i <= 1000; i++)
+        {
+            cksum[5] += (double)i * _x[i];
+        }
+
+        /* loop 6      tri-diagonal elimination, above diagonal */
+
+        Init();
+        ts[6] = (double)Clock();
+        for (j = 3; j <= 999; j += 3)
+        {
+            i = 1003 - j;
+            _x[i] = _x[i] - _z[i] * _x[i + 1];
+            _x[i - 1] = _x[i - 1] - _z[i - 1] * _x[i];
+            _x[i - 2] = _x[i - 2] - _z[i - 2] * _x[i - 1];
+        }
+        ts[6] = (double)Clock() - ts[6];
+        for (j = 1; j <= 999; j++)
+        {
+            l = 1001 - j;
+            cksum[6] += (double)j * _x[l];
+        }
+
+        /* loop 7      equation of state excerpt */
+
+        Init();
+        ts[7] = (double)Clock();
+        for (m = 1; m <= 120; m++)
+        {
+            _x[m] = _u[m] + r * (_z[m] + r * _y[m]) + t * (_u[m + 3] + r * (_u[m + 2] + r * _u[m + 1]) + t * (_u[m + 6] + r * (_u[m + 5] + r * _u[m + 4])));
+        }
+        ts[7] = (double)Clock() - ts[7];
+        for (m = 1; m <= 120; m++)
+        {
+            cksum[7] += (double)m * _x[m];
+        }
+
+        /* loop 8      p.d.e. integration */
+
+        Init();
+        ts[8] = (double)Clock();
+        nl1 = 1;
+        nl2 = 2;
+        for (kx = 2; kx <= 3; kx++)
+        {
+            for (ky = 2; ky <= 21; ky++)
+            {
+                du1 = _u1[kx][ky + 1][nl1] - _u1[kx][ky - 1][nl1];
+                du2 = _u2[kx][ky + 1][nl1] - _u2[kx][ky - 1][nl1];
+                du3 = _u3[kx][ky + 1][nl1] - _u3[kx][ky - 1][nl1];
+                _u1[kx][ky][nl2] = _u1[kx][ky][nl1] + a11 * du1 + a12 * du2 + a13 * du3 + sig * (_u1[kx + 1][ky][nl1]
+                   - 2.0 * _u1[kx][ky][nl1] + _u1[kx - 1][ky][nl1]);
+                _u2[kx][ky][nl2] = _u2[kx][ky][nl1] + a21 * du1 + a22 * du2 + a23 * du3 + sig * (_u2[kx + 1][ky][nl1]
+                   - 2.0 * _u2[kx][ky][nl1] + _u2[kx - 1][ky][nl1]);
+                _u3[kx][ky][nl2] = _u3[kx][ky][nl1] + a31 * du1 + a32 * du2 + a33 * du3 + sig * (_u3[kx + 1][ky][nl1]
+                   - 2.0 * _u3[kx][ky][nl1] + _u3[kx - 1][ky][nl1]);
+            }
+        }
+        ts[8] = (double)Clock() - ts[8];
+        for (i = 1; i <= 2; i++)
+        {
+            for (kx = 2; kx <= 3; kx++)
+            {
+                for (ky = 2; ky <= 21; ky++)
+                {
+                    cksum[8] += (double)kx * (double)ky * (double)i * (_u1[kx][ky][i] + _u2[kx][ky][i] + _u3[kx][ky][i]);
+                }
+            }
+        }
+
+        /* loop 9      integrate predictors */
+
+        Init();
+        ts[9] = (double)Clock();
+        for (i = 1; i <= 100; i++)
+        {
+            _px[1][i] = b28 * _px[13][i] + b27 * _px[12][i] + b26 * _px[11][i] + b25 * _px[10][i] + b24 * _px[9][i] +
+               b23 * _px[8][i] + b22 * _px[7][i] + c0 * (_px[5][i] + _px[6][i]) + _px[3][i];
+        }
+        ts[9] = (double)Clock() - ts[9];
+        for (i = 1; i <= 100; i++)
+        {
+            cksum[9] += (double)i * _px[1][i];
+        }
+
+        /* loop 10     difference predictors */
+
+        Init();
+        ts[10] = (double)Clock();
+        for (i = 1; i <= 100; i++)
+        {
+            ar = _cx[5][i];
+            br = ar - _px[5][i];
+            _px[5][i] = ar;
+            cr = br - _px[6][i];
+            _px[6][i] = br;
+            ar = cr - _px[7][i];
+            _px[7][i] = cr;
+            br = ar - _px[8][i];
+            _px[8][i] = ar;
+            cr = br - _px[9][i];
+            _px[9][i] = br;
+            ar = cr - _px[10][i];
+            _px[10][i] = cr;
+            br = ar - _px[11][i];
+            _px[11][i] = ar;
+            cr = br - _px[12][i];
+            _px[12][i] = br;
+            _px[14][i] = cr - _px[13][i];
+            _px[13][i] = cr;
+        }
+        ts[10] = (double)Clock() - ts[10];
+        for (i = 1; i <= 100; i++)
+        {
+            for (k = 5; k <= 14; k++)
+            {
+                cksum[10] += (double)k * (double)i * _px[k][i];
+            }
+        }
+
+        /* loop 11     first sum. */
+
+        Init();
+        ts[11] = (double)Clock();
+        _x[1] = _y[1];
+        for (k = 2; k <= 1000; k++)
+        {
+            _x[k] = _x[k - 1] + _y[k];
+        }
+        ts[11] = (double)Clock() - ts[11];
+        for (k = 1; k <= 1000; k++)
+        {
+            cksum[11] += (double)k * _x[k];
+        }
+
+        /* loop 12     first diff. */
+
+        Init();
+        ts[12] = (double)Clock();
+        for (k = 1; k <= 999; k++)
+        {
+            _x[k] = _y[k + 1] - _y[k];
+        }
+        ts[12] = (double)Clock() - ts[12];
+        for (k = 1; k <= 999; k++)
+        {
+            cksum[12] += (double)k * _x[k];
+        }
+
+        /* loop 13      2-d particle pusher */
+
+        Init();
+        ts[13] = (double)Clock();
+        for (ip = 1; ip <= 128; ip++)
+        {
+            i1 = (int)_p[1][ip];
+            j1 = (int)_p[2][ip];
+            _p[3][ip] += _b[i1][j1];
+            _p[4][ip] += _c[i1][j1];
+            _p[1][ip] += _p[3][ip];
+            _p[2][ip] += _p[4][ip];
+            // Each element of m_p, m_b and m_c is initialized to 1.00025 in Init().
+            // From the assignments above,
+            // i2 = m_p[1][ip] = m_p[1][ip] + m_p[3][ip] = m_p[1][ip] + m_p[3][ip] + m_b[i1][j1] = 1 + 1 + 1 = 3
+            // j2 = m_p[2][ip] = m_p[2][ip] + m_p[4][ip] = m_p[2][ip] + m_p[4][ip] + m_c[i1][j1] = 1 + 1 + 1 = 3
+            i2 = (int)_p[1][ip];
+            j2 = (int)_p[2][ip];
+            // Accessing m_y, m_z upto 35
+            _p[1][ip] += _y[i2 + 32];
+            _p[2][ip] += _z[j2 + 32];
+
+            i2 += _e[i2 + 32];
+            j2 += _f[j2 + 32];
+            _h[i2][j2] += 1.0;
+        }
+        ts[13] = (double)Clock() - ts[13];
+        for (ip = 1; ip <= 128; ip++)
+        {
+            cksum[13] += (double)ip * (_p[3][ip] + _p[4][ip] + _p[1][ip] + _p[2][ip]);
+        }
+        for (k = 1; k <= 64; k++)
+        {
+            for (ix = 1; ix <= 8; ix++)
+            {
+                cksum[13] += (double)k * (double)ix * _h[k][ix];
+            }
+        }
+
+        /* loop 14      1-d particle pusher */
+
+        Init();
+        ts[14] = (double)Clock();
+        for (k = 1; k <= 150; k++)
+        {
+            // m_grd[150] = 13.636
+            // Therefore ix <= 13
+            ix = (int)_grd[k];
+            xi = (double)ix;
+            _vx[k] += _ex[ix] + (_xx[k] - xi) * _dex[ix];
+            _xx[k] += _vx[k] + flx;
+            ir = (int)_xx[k];
+            ri = (double)ir;
+            rx1 = _xx[k] - ri;
+            ir = System.Math.Abs(ir % 64);
+            _xx[k] = ri + rx1;
+            // ir < 64 since ir = ir % 64
+            // So m_rh is accessed upto 64
+            _rh[ir] += 1.0 - rx1;
+            _rh[ir + 1] += rx1;
+        }
+        ts[14] = (double)Clock() - ts[14];
+        for (k = 1; k <= 150; k++)
+        {
+            cksum[14] += (double)k * (_vx[k] + _xx[k]);
+        }
+        for (k = 1; k <= 67; k++)
+        {
+            cksum[14] += (double)k * _rh[k];
+        }
+
+        /* time the clock call */
+
+        ts[15] = (double)Clock();
+        ts[15] = (double)Clock() - ts[15];
+
+        /* scale= set to convert time to micro-seconds */
+
+        scale = 1.0;
+        rt[15] = ts[15] * scale;
+
+        nt = 14;
+        t = s = uu = 0.0;
+        for (k = 1; k <= nt; k++)
+        {
+            rt[k] = (ts[k] - ts[15]) * scale;
+            t += rt[k];
+            mops[k] = _nrops[k] * _loops[k];
+            s += (double)mops[k];
+            rpm[k] = 0.0;
+            if (rt[k] != 0.0)
+            {
+                rpm[k] = (double)mops[k] / rt[k];
+            }
+            uu += rpm[k];
+        }
+        uu /= (double)nt;
+        s /= t;
+
+        // Ensure that the array elements are live-out
+        Escape(ts);
+        Escape(rt);
+        Escape(rpm);
+        Escape(cksum);
+        Escape(mops);
+    }
+
+    private void Init()
+    {
+        int j, k, l;
+
+        for (k = 1; k <= 1000; k++)
+        {
+            _x[k] = 1.11;
+            _y[k] = 1.123;
+            _z[k] = 0.321;
+        }
+
+        for (k = 1; k <= 500; k++)
+        {
+            _u[k] = 0.00025;
+        }
+
+        for (k = 1; k <= 15; k++)
+        {
+            for (l = 1; l <= 100; l++)
+            {
+                _px[k][l] = l;
+                _cx[k][l] = l;
+            }
+        }
+
+        for (j = 1; j < 6; j++)
+        {
+            for (k = 1; k < 23; k++)
+            {
+                for (l = 1; l < 3; l++)
+                {
+                    _u1[j][k][l] = k;
+                    _u2[j][k][l] = k + k;
+                    _u3[j][k][l] = k + k + k;
+                }
+            }
+        }
+
+        for (j = 1; j < 65; j++)
+        {
+            for (k = 1; k < 9; k++)
+            {
+                _b[j][k] = 1.00025;
+                _c[j][k] = 1.00025;
+                _h[j][k] = 1.00025;
+            }
+        }
+
+        for (j = 1; j < 6; j++)
+        {
+            _bnk1[j] = j * 100;
+            _bnk2[j] = j * 110;
+            _bnk3[j] = j * 120;
+            _bnk4[j] = j * 130;
+            _bnk5[j] = j * 140;
+        }
+
+        for (j = 1; j < 5; j++)
+        {
+            for (k = 1; k < 513; k++)
+            {
+                _p[j][k] = 1.00025;
+            }
+        }
+
+        for (j = 1; j < 193; j++)
+        {
+            _e[j] = _f[j] = 1;
+        }
+
+        for (j = 1; j < 68; j++)
+        {
+            _ex[j] = _rh[j] = _dex[j] = (double)j;
+        }
+
+        for (j = 1; j < 151; j++)
+        {
+            _vx[j] = 0.001;
+            _xx[j] = 0.001;
+            _grd[j] = (double)(j / 8 + 3);
+        }
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        var lloops = new LLoops();
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                lloops.Bench();
+            }
+        }
+    }
+
+    private bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        var lloops = new LLoops();
+        bool result = lloops.TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/LLoops/LLoops.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/LLoops/LLoops.csproj
new file mode 100644 (file)
index 0000000..636c5e7
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="LLoops.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Lorenz/Lorenz.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Lorenz/Lorenz.cs
new file mode 100644 (file)
index 0000000..bff6398
--- /dev/null
@@ -0,0 +1,134 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// This program solves the "lorenz" equations using Runge-Kutta 4
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Lorenz
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 8000000;
+#endif
+
+    private static double s_t = 0.0;
+    private static double s_x = 5.0;
+    private static double s_y = 2.0;
+    private static double s_z = 27.0;
+
+    private static int s_nsteps = Iterations;
+    private static double s_h = -1.0;
+    private static int s_printDerivative = -1;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double k1, k2, k3, k4;
+        double l1, l2, l3, l4;
+        double m1, m2, m3, m4;
+        double hdiv2, hdiv6;
+        int i;
+
+        if (s_h < 0.0)
+        {
+            s_h = 20.0 / (double)s_nsteps;
+        }
+        if (s_printDerivative < 0)
+        {
+            s_printDerivative = s_nsteps;
+        }
+
+        hdiv2 = s_h / 2.0;
+        hdiv6 = s_h / 6.0;
+
+        for (i = 0; i < s_nsteps; ++i)
+        {
+            double t_arg, x_arg, y_arg, z_arg;
+
+            k1 = F(s_t, s_x, s_y, s_z);
+            l1 = G(s_t, s_x, s_y, s_z);
+            m1 = H(s_t, s_x, s_y, s_z);
+
+            t_arg = s_t + hdiv2;
+            x_arg = s_x + hdiv2 * k1;
+            y_arg = s_y + hdiv2 * l1;
+            z_arg = s_z + hdiv2 * m1;
+
+            k2 = F(t_arg, x_arg, y_arg, z_arg);
+            l2 = G(t_arg, x_arg, y_arg, z_arg);
+            m2 = H(t_arg, x_arg, y_arg, z_arg);
+
+            x_arg = s_x + hdiv2 * k2;
+            y_arg = s_y + hdiv2 * l2;
+            z_arg = s_z + hdiv2 * m2;
+
+            k3 = F(t_arg, x_arg, y_arg, z_arg);
+            l3 = G(t_arg, x_arg, y_arg, z_arg);
+            m3 = H(t_arg, x_arg, y_arg, z_arg);
+
+            t_arg = s_t + s_h;
+            x_arg = s_x + s_h * k3;
+            y_arg = s_y + s_h * l3;
+            z_arg = s_z + s_h * m3;
+
+            k4 = F(t_arg, x_arg, y_arg, z_arg);
+            l4 = G(t_arg, x_arg, y_arg, z_arg);
+            m4 = H(t_arg, x_arg, y_arg, z_arg);
+
+            s_x = s_x + hdiv6 * (k1 + 2.0 * k2 + 2.0 * k3 + k4);
+            s_y = s_y + hdiv6 * (l1 + 2.0 * l2 + 2.0 * l3 + l4);
+            s_z = s_z + hdiv6 * (m1 + 2.0 * m2 + 2.0 * m3 + m4);
+            s_t = t_arg;
+        }
+
+        return true;
+    }
+
+    private static double F(double t, double x, double y, double z)
+    {
+        return (10.0 * (y - x));
+    }
+
+    private static double G(double t, double x, double y, double z)
+    {
+        return (x * (28.0 - z) - y);
+    }
+
+    private static double H(double t, double x, double y, double z)
+    {
+        return (x * y - (8.0 * z) / 3.0);
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Lorenz/Lorenz.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Lorenz/Lorenz.csproj
new file mode 100644 (file)
index 0000000..1006638
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Lorenz.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/MatInv4/MatInv4.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/MatInv4/MatInv4.cs
new file mode 100644 (file)
index 0000000..f90aa63
--- /dev/null
@@ -0,0 +1,495 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class LLoops
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 60;
+#endif
+
+    private static float s_det;
+
+    private struct X
+    {
+        public float[] A;
+        public X(int size)
+        {
+            A = new float[size];
+        }
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        X a = new X(Iterations * Iterations);
+        float[] b = new float[Iterations * Iterations];
+        float[] c = new float[Iterations * Iterations];
+        float[] d = new float[Iterations * Iterations];
+        float[] l1 = new float[Iterations];
+        float[] l2 = new float[Iterations];
+
+        int i, k, n, nsq;
+
+        n = Iterations;
+        nsq = n * n;
+        for (i = 0; i < n; ++i)
+        {
+            for (k = 0; k < n; ++k)
+            {
+                if (i == k)
+                {
+                    a.A[i * n + k] = 40.0F;
+                }
+                else
+                {
+                    a.A[i * n + k] = 0.0F;
+                }
+            }
+        }
+
+        for (i = 0; i < n; ++i)
+        {
+            for (k = i; k < nsq; k += n)
+            {
+                b[k] = a.A[k];
+            }
+        }
+
+        /*** second(&t1); ***/
+
+        MinV1(b, ref n, out s_det, l1, l2);
+
+        if (s_det == 0.0F)
+        {
+            goto L990;
+        }
+
+        /*** second(&tx); ***/
+
+        MProd(b, a.A, c, ref n);
+        for (k = 1; k <= nsq; ++k)
+        {
+            b[k - 1] = a.A[k - 1];
+        }
+
+        /*** second(&tx); ***/
+
+        MinV2(b, ref n, out s_det, l1, l2);
+
+        if (s_det == 0.0F)
+        {
+            goto L990;
+        }
+
+        /*** second(&ty); ***/
+
+        MProd(b, a.A, d, ref n);
+        CompM(c, d, ref n);
+
+        /*** second(&t2); ***/
+
+        return true;
+
+    L990:
+        {
+        }
+
+        return true;
+    }
+
+    private static void MinV1(float[] a, ref int n, out float d, float[] l, float[] m)
+    {
+        float biga, hold;
+        int i, j, k, ij, ik, ji, jk, nk, ki, kj, kk, iz, jp, jq, jr;
+
+        d = 1.0F;
+        ji = 0;
+        hold = 0.0F;
+        nk = -n;
+        for (k = 1; k <= n; ++k)
+        {
+            nk = nk + n;
+            l[k - 1] = k;
+            m[k - 1] = k;
+            kk = nk + k;
+            biga = a[kk - 1];
+            for (j = k; j <= n; ++j)
+            {
+                // j <= n, so iz <= n^2 - n
+                iz = n * (j - 1);
+                for (i = k; i <= n; ++i)
+                {
+                    // iz <= n^2 - n and i <= n, so ij <= n^2
+                    ij = iz + i;
+                    if (System.Math.Abs(biga) >= System.Math.Abs(a[ij - 1]))
+                    {
+                        continue;
+                    }
+                    // accessing up to n^2 - 1
+                    biga = a[ij - 1];
+                    l[k - 1] = i;
+                    m[k - 1] = j;
+                }
+            }
+
+            j = (int)l[k - 1];
+
+            if (j <= k)
+            {
+                goto L35;
+            }
+
+            // -n < ki <= 0
+            ki = k - n;
+            for (i = 1; i <= n; ++i)
+            {
+                // i <= n, ki <= n + n + ... + n (n times) i.e. k <= n * n (when ki = 0 initially)
+                ki = ki + n;
+                // Accessing upto n^2 -1
+                hold = -a[ki - 1];
+                // ji <= n^2 - n + n (for ki = 0 initially when k = n and 0 < j <= n)
+                // Therefore ji <= n^2
+                ji = ki - k + j;
+                a[ki - 1] = a[ji - 1];
+                a[ji - 1] = hold;
+            }
+        L35:
+            i = (int)m[k - 1];
+            if (i <= k)
+            {
+                goto L45;
+            }
+
+            // 0 <= jp <= n^2 - n
+            jp = n * (i - 1);
+            for (j = 1; j <= n; ++j)
+            {
+                // 0 < nk <= n * (n-1)
+                // jk <= n^2 - n + n
+                // jk <= n^2
+                jk = nk + j;
+                // jp <= n^2 - n
+                // ji <= n^2 - n + n or ji <= n^2 (since 0 < j <= n)
+                ji = jp + j;
+                hold = -a[jk - 1];
+                a[jk - 1] = a[ji - 1];
+                a[ji - 1] = hold;
+            }
+        L45:
+            if (biga != 0.0F)
+            {
+                goto L48;
+            }
+            d = 0.0F;
+            return;
+
+        L48:
+            for (i = 1; i <= n; ++i)
+            {
+                if (i == k)
+                {
+                    break;
+                }
+                // 0 < nk <= n * (n-1)
+                // 0 < ik <= n^2
+                ik = nk + i;
+                a[ik - 1] = a[ik - 1] / (-biga);
+            }
+
+            for (i = 1; i <= n; ++i)
+            {
+                if (i == k)
+                {
+                    continue;
+                }
+                // 0 < nk <= n * (n-1)
+                // 0 < ik <= n^2
+                ik = nk + i;
+                hold = a[ik - 1];
+                // -n < ij <= 0 
+                ij = i - n;
+                for (j = 1; j <= n; ++j)
+                {
+                    // i <= n, ij <= n + n + ... + n (n times) or ij <= n * n 
+                    ij = ij + n;
+                    if (j == k)
+                    {
+                        continue;
+                    }
+                    // if i=1, kj = (1 + (n-1) * n) - 1 + n ==> ij = n^2
+                    // if i=n, kj = (n * n) - n + n ==> ij = n ^2
+                    // So j <= n^2
+                    kj = ij - i + k;
+                    a[ij - 1] = hold * a[kj - 1] + a[ij - 1];
+                }
+            }
+            kj = k - n;
+            for (j = 1; j <= n; ++j)
+            {
+                // k <= n, kj <= n + n + ... + n (n times) or kj <= n * n 
+                kj = kj + n;
+                if (j == k)
+                {
+                    continue;
+                }
+                // Accessing upto n^2 - 1
+                a[kj - 1] = a[kj - 1] / biga;
+            }
+            d = d * biga;
+            a[kk - 1] = 1.0F / biga;
+        }
+        k = n;
+    L100:
+        k = k - 1;
+        if (k < 1)
+        {
+            return;
+        }
+        i = (int)l[k - 1];
+        if (i <= k)
+        {
+            goto L120;
+        }
+
+        // 0 <= jq <= n^2 - n
+        // 0 <= jr <= n^2 - n
+        jq = n * (k - 1);
+        jr = n * (i - 1);
+        for (j = 1; j <= n; ++j)
+        {
+            // jk <= n^2 - n + n 
+            // jk <= n^2
+            jk = jq + j;
+            hold = a[jk - 1];
+            // ji <= n^2 - n + n 
+            // ji <= n^2
+            ji = jr + j;
+            a[jk - 1] = -a[ji - 1];
+            a[ji - 1] = hold;
+        }
+    L120:
+        j = (int)m[k - 1];
+        if (j <= k)
+        {
+            goto L100;
+        }
+        // 0 <= jr <= n^2 - n
+        ki = k - n;
+        for (i = 1; i <= n; ++i)
+        {
+            // ki <= n + n + ... + n (n times) or ki <= n * n 
+            ki = ki + n;
+            hold = a[ki - 1];
+            // if i=1, ji = (1 + (n-1) * n) - 1 + n ==> ij = n^2
+            // if i=n, ji = (n * n) - n + n ==> ij = n ^2
+            // Therefore ji <= n^2
+            ji = ki - k + j;
+            a[ki - 1] = -a[ji - 1];
+        }
+        a[ji - 1] = hold;
+        goto L100;
+    }
+
+    private static void MinV2(float[] a, ref int n, out float d, float[] l, float[] m)
+    {
+        float biga, hold;
+        int i, j, k;
+
+        d = 1.0F;
+        for (k = 1; k <= n; ++k)
+        {
+            l[k - 1] = k;
+            m[k - 1] = k;
+            biga = a[(k - 1) * n + (k - 1)];
+            for (j = k; j <= n; ++j)
+            {
+                for (i = k; i <= n; ++i)
+                {
+                    // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+                    if (System.Math.Abs(biga) >= System.Math.Abs(a[(i - 1) * n + (j - 1)]))
+                    {
+                        continue;
+                    }
+                    biga = a[(i - 1) * n + (j - 1)];
+                    l[k - 1] = i;
+                    m[k - 1] = j;
+                }
+            }
+            j = (int)l[k - 1];
+            if (l[k - 1] <= k)
+            {
+                goto L200;
+            }
+            for (i = 1; i <= n; ++i)
+            {
+                // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+                hold = -a[(k - 1) * n + (i - 1)];
+                a[(k - 1) * n + (i - 1)] = a[(j - 1) * n + (i - 1)];
+                a[(j - 1) * n + (i - 1)] = hold;
+            }
+        L200:
+            i = (int)m[k - 1];
+            if (m[k - 1] <= k)
+            {
+                goto L250;
+            }
+            for (j = 1; j <= n; ++j)
+            {
+                // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+                hold = -a[(j - 1) * n + (k - 1)];
+                a[(j - 1) * n + (k - 1)] = a[(j - 1) * n + (i - 1)];
+                a[(j - 1) * n + (i - 1)] = hold;
+            }
+        L250:
+            if (biga != 0.0F)
+            {
+                goto L300;
+            }
+            d = 0.0F;
+            return;
+
+        L300:
+            for (i = 1; i <= n; ++i)
+            {
+                if (i != k)
+                {
+                    // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+                    a[(i - 1) * n + (k - 1)] = a[(i - 1) * n + (k - 1)] / (-biga);
+                }
+            }
+            for (i = 1; i <= n; ++i)
+            {
+                if (i == k)
+                {
+                    continue;
+                }
+                for (j = 1; j <= n; ++j)
+                {
+                    if (j != k)
+                    {
+                        // Accessing upto n^2 - n + n - 1 ==> n^2 - 1                            
+                        a[(i - 1) * n + (j - 1)] = a[(i - 1) * n + (k - 1)] * a[(k - 1) * n + (j - 1)] + a[(i - 1) * n + (j - 1)];
+                    }
+                }
+            }
+            for (j = 1; j < n; ++j)
+            {
+                if (j != k)
+                {
+                    // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+                    a[(k - 1) * n + (j - 1)] = a[(k - 1) * n + (j - 1)] / biga;
+                }
+            }
+            d = d * biga;
+            a[(k - 1) * n + (k - 1)] = 1.0F / biga;
+        }
+        k = n;
+    L400:
+        k = k - 1;
+        if (k < 1)
+        {
+            return;
+        }
+        i = (int)l[k - 1];
+        if (i <= k)
+        {
+            goto L450;
+        }
+        for (j = 1; j <= n; ++j)
+        {
+            // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+            hold = a[(j - 1) * n + (k - 1)];
+            a[(j - 1) * n + (k - 1)] = -a[(j - 1) * n + (i - 1)];
+            a[(j - 1) * n + (i - 1)] = hold;
+        }
+    L450:
+        j = (int)m[k - 1];
+        if (j <= k)
+        {
+            goto L400;
+        }
+        for (i = 1; i <= n; ++i)
+        {
+            // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+            hold = a[(k - 1) * n + (i - 1)];
+            a[(k - 1) * n + (i - 1)] = -a[(j - 1) * n + (i - 1)];
+            a[(j - 1) * n + (i - 1)] = hold;
+        }
+        goto L400;
+    }
+
+    private static void MProd(float[] a, float[] b, float[] c, ref int n)
+    {
+        int i, j, k;
+
+        for (i = 1; i <= n; ++i)
+        {
+            for (j = 1; j <= n; ++j)
+            {
+                // Accessing upto n^2 - n + n - 1 ==> n^2 - 1
+                c[(i - 1) * n + (j - 1)] = 0.0F;
+                for (k = 1; k <= n; ++k)
+                {
+                    c[(i - 1) * n + (j - 1)] = c[(i - 1) * n + (j - 1)] + a[(i - 1) * n + (k - 1)] * b[(k - 1) * n + (j - 1)];
+                }
+            }
+        }
+        return;
+    }
+
+    private static void CompM(float[] a, float[] b, ref int n)
+    {
+        int i, j;
+        float x, sum = 0.0F;
+
+        //(starting compare.)
+        for (i = 1; i <= n; ++i)
+        {
+            for (j = 1; j <= n; ++j)
+            {
+                x = 0.0F;
+                if (i == j)
+                {
+                    x = 1.0F;
+                }
+                sum = sum + System.Math.Abs(System.Math.Abs(a[(i - 1) * n + (j - 1)]) - x);
+            }
+        }
+        return;
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/MatInv4/MatInv4.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/MatInv4/MatInv4.csproj
new file mode 100644 (file)
index 0000000..dc87665
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="MatInv4.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.cs
new file mode 100644 (file)
index 0000000..0fc1413
--- /dev/null
@@ -0,0 +1,135 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// Simultaneous equations by Newton's method adapted from Conte and De Boor
+// to solve F(X,Y)=0 and G(X,Y)=0
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class NewtE
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 1000000;
+#endif
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double idgb, a, b, x, y, deltaX, deltaY;
+        a = 0;
+        b = 0;
+        x = 0;
+        y = 0;
+        idgb = 0;
+
+        if (idgb != 0)
+        {
+            System.Console.WriteLine("{0}, {1}, F(x,y) , G(x,y) \n", x, y);
+        }
+
+        for (int j = 1; j <= Iterations; j++)
+        {
+            x = 1.0;
+            y = (-2.0);
+            a = F(x, y);
+            b = G(x, y);
+            if (idgb != 0)
+            {
+                System.Console.WriteLine(" {0}, {1}, {2}, {3}\n", x, y, a, b);
+            }
+
+            for (int i = 1; i <= 20; i++)
+            {
+                deltaX = (-F(x, y) * GY(x, y) + G(x, y) * FY(x, y)) / (FX(x, y) * GY(x, y) - FY(x, y) * GX(x, y));
+                deltaY = (-G(x, y) * FX(x, y) + F(x, y) * GX(x, y)) / (FX(x, y) * GY(x, y) - FY(x, y) * GX(x, y));
+                x = x + deltaX;
+                y = y + deltaY;
+                a = F(x, y);
+                b = G(x, y);
+                if (idgb != 0)
+                {
+                    System.Console.WriteLine("{0}, {1}, {2}, {3}, {4}\n", i, x, y, a, b);
+                }
+
+                if ((System.Math.Abs(deltaX) < 0.000001) && (System.Math.Abs(deltaY) < 0.000001) &&
+                   (System.Math.Abs(a) < 0.000001) && (System.Math.Abs(b) < 0.000001))
+                {
+                    goto L11;
+                }
+            }
+            if (idgb != 0)
+            {
+                System.Console.WriteLine("FAILED TO CONVERGE IN 20 ITERATIONS\n");
+            }
+
+        L11:
+            {
+            }
+        }
+
+        return true;
+    }
+
+    private static double F(double x, double y)
+    {
+        return ((x) + 3 * System.Math.Log(x) / System.Math.Log(10.0) - (y) * (y));
+    }
+
+    private static double G(double x, double y)
+    {
+        return (2 * (x) * (x) - (x) * (y) - 5 * (x) + 1);
+    }
+
+    private static double FX(double x, double y)
+    {
+        return (1 + 3 / (System.Math.Log(10.0) * (x)));
+    }
+
+    private static double FY(double x, double y)
+    {
+        return ((-2) * (y));
+    }
+
+    private static double GX(double x, double y)
+    {
+        return (4 * (x) - (y) - 5);
+    }
+
+    private static double GY(double x, double y)
+    {
+        return (-(x));
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/NewtE/NewtE.csproj
new file mode 100644 (file)
index 0000000..7f3ba35
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="NewtE.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/NewtR/NewtR.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/NewtR/NewtR.cs
new file mode 100644 (file)
index 0000000..cf945bc
--- /dev/null
@@ -0,0 +1,131 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// Newton's method adapted from Conte and De Boor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class NewtR
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 80000000;
+#endif
+
+    public static volatile object VolatileObject;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static void Escape(object obj)
+    {
+        VolatileObject = obj;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        int idbg, iflag;
+        double x0, fx0;
+
+        iflag = 0;
+        idbg = 0;
+        fx0 = 0.0;
+        x0 = 1.0;
+
+        for (int i = 1; i <= Iterations; i++)
+        {
+            Inner(ref x0, 0.0000001, 0.0000001, 10, out iflag);
+            if (iflag > 1)
+            {
+                goto L888;
+            }
+
+            fx0 = FF(x0);
+            if (idbg != 0)
+            {
+                System.Console.WriteLine(" THE ROOT IS {0:e} F(ROOT) := {1:E}\n", x0, fx0);
+            }
+
+        L888:
+            {
+            }
+        }
+
+        // Escape iflag, x0, and fx0 so that they appear live
+        Escape(iflag);
+        Escape(x0);
+        Escape(fx0);
+
+        return true;
+    }
+
+    private static double FF(double x)
+    {
+        return (-1.0 - ((x) * (1.0 - ((x) * (x)))));
+    }
+
+    private static double FFDer(double x)
+    {
+        return (3.0 * (x) * (x) - 1.0);
+    }
+
+    private static void Inner(ref double x0, double xtol, double ftol, int ntol, out int iflag)
+    {
+        double fx0, deriv, deltax;
+
+        iflag = 0;
+        for (int n = 1; n <= ntol; n++)
+        {
+            fx0 = FF(x0);
+            if (System.Math.Abs(fx0) < ftol)
+            {
+                goto L999;
+            }
+            deriv = FFDer(x0);
+
+            if (deriv == 0.0)
+            {
+                goto L999;
+            }
+            deltax = fx0 / deriv;
+            x0 = x0 - deltax;
+            if (System.Math.Abs(deltax) < xtol)
+            {
+                goto L999;
+            }
+        }
+    L999:
+        iflag = 2;
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/NewtR/NewtR.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/NewtR/NewtR.csproj
new file mode 100644 (file)
index 0000000..acb60b3
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="NewtR.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Regula/Regula.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Regula/Regula.cs
new file mode 100644 (file)
index 0000000..83af3a4
--- /dev/null
@@ -0,0 +1,193 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// The modified regula-falsi routine adapted from Conte and De Boor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Adams
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 4000000;
+#endif
+
+    public static volatile object VolatileObject;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static void Escape(object obj)
+    {
+        VolatileObject = obj;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double error, fxi;
+        double a, b, xi;
+        int idbg, iflag;
+
+        iflag = 0;
+        idbg = 0;
+        xi = 0;
+        error = 0.0;
+        fxi = 0.0;
+
+        for (int i = 1; i <= Iterations; i++)
+        {
+            a = 1.0;
+            b = 2.0;
+            Inner(ref a, ref b, 0.0000001, 0.0000000001, 30, out iflag);
+            if (iflag > 2)
+            {
+                goto L999;
+            }
+
+            xi = (a + b) / 2.0;
+            error = System.Math.Abs(b - a) / 2.0;
+            fxi = FG(xi);
+
+            if (idbg != 0)
+            {
+                System.Console.WriteLine(" the root is  {0:E}", xi);
+                System.Console.WriteLine(" plus/minus {0}\n", error);
+                System.Console.WriteLine(" fg(root):= {0:E}\n", fxi);
+            }
+
+        L999:
+            {
+            }
+        }
+
+        // Escape iflag, xi, error, and fxi so that they appear live
+        Escape(iflag);
+        Escape(xi);
+        Escape(error);
+        Escape(fxi);
+
+        return true;
+    }
+
+    private static double FG(double x)
+    {
+        return (-1.0 - (x * (1.0 - (x * x))));
+    }
+
+    private static void Inner(ref double a, ref double b, double xtol, double ftol, int ntol, out int iflag)
+    {
+        double signfa, prevfw, fa, fb, fw, w;
+
+        iflag = 0;
+        fa = FG(a);
+        if (fa < 0.0)
+        {
+            signfa = -1.0;
+        }
+        else
+        {
+            signfa = 1.0;
+        }
+
+        fb = FG(b);
+        if (signfa * fb <= 0.0)
+        {
+            goto L5;
+        }
+
+        iflag = 3;
+        goto L99;
+
+    L5:
+        w = a;
+        fw = fa;
+        for (int i = 1; i <= ntol; i++)
+        {
+            if (System.Math.Abs(b - a) / 2.0 <= xtol)
+            {
+                goto L99;
+            }
+            if (System.Math.Abs(fw) > ftol)
+            {
+                goto L9;
+            }
+
+            a = w;
+            b = w;
+            iflag = 1;
+            goto L99;
+
+        L9:
+            w = (fa * b - fb * a) / (fa - fb);
+            if (fw < 0.0)
+            {
+                prevfw = -1.0;
+            }
+            else
+            {
+                prevfw = 1.0;
+            }
+            fw = FG(w);
+
+            if (signfa * fw < 0.0)
+            {
+                goto L10;
+            }
+            a = w;
+            fa = fw;
+            if (fw * prevfw > 0.0)
+            {
+                fb = fb / 2.0;
+            }
+            goto L20;
+
+        L10:
+            b = w;
+            fb = fw;
+            if (fw * prevfw > 0.0)
+            {
+                fa = fa / 2.0;
+            }
+
+        L20:
+            {
+            }
+        }
+
+        iflag = 2;
+    L99:
+        {
+        }
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Regula/Regula.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Regula/Regula.csproj
new file mode 100644 (file)
index 0000000..aeaf007
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Regula.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Romber/Romber.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Romber/Romber.cs
new file mode 100644 (file)
index 0000000..5824cd4
--- /dev/null
@@ -0,0 +1,169 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// Integration by romberg method adapted from Conte and de Boor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Romber
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 640000;
+#endif
+
+    private static T[][] AllocArray<T>(int n1, int n2)
+    {
+        T[][] a = new T[n1][];
+        for (int i = 0; i < n1; ++i)
+        {
+            a[i] = new T[n2];
+        }
+        return a;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double[][] r = AllocArray<double>(11, 11);
+        double[][] t = AllocArray<double>(11, 11);
+
+        int idbg, m, n, i, kmax, fourj, j, kmaxm2, l, k, mm1;
+        double sum, ratio, t1, h, a, b;
+
+        for (l = 1; l <= Iterations; l++)
+        {
+            idbg = 0;
+            m = 2;
+            kmax = 6;
+            a = 0;
+            b = 1;
+            h = (b - a) / (m);
+            sum = (F(a) + F(b)) / 2;
+
+            mm1 = m - 1;
+            if (mm1 < 0)
+            {
+                goto L40;
+            }
+            if (mm1 == 0)
+            {
+                goto L10;
+            }
+            for (i = 1; i <= mm1; i++)
+            {
+                t1 = a + i * h;
+                sum = sum + F(t1);
+            }
+
+        L10:
+            t[1][1] = sum * h;
+            if (idbg != 0)
+            {
+                System.Console.WriteLine(" romberg t-table \n");
+                System.Console.WriteLine("{0}\n", t[1][1]);
+            }
+
+            for (k = 2; k <= kmax; k++)
+            {
+                h = h / 2;
+                n = m * 2;
+                sum = 0;
+                for (i = 1; i <= n / 2; i++)
+                {
+                    r[k][1] = r[k - 1][1] * System.Math.Sqrt(b * mm1);
+                    t1 = a + i * h;
+                    sum = sum + F(t1);
+                }
+
+                t[k][1] = t[k - 1][1] / 2 + sum * h;
+                fourj = 1;
+                for (j = 2; j <= k; j++)
+                {
+                    fourj = fourj * 4;
+                    t[k - 1][j - 1] = t[k][j - 1] - t[k - 1][j - 1];
+                    t[k][j] = t[k][j - 1] + t[k - 1][j - 1] / (fourj - 1);
+                }
+
+                if (idbg != 0)
+                {
+                    j = 1;
+                    System.Console.WriteLine("{0} {1} {2}d\n", t[k][j], j, k);
+                }
+            }
+
+            kmaxm2 = kmax - 2;
+            if (kmaxm2 <= 0)
+            {
+                goto L40;
+            }
+
+            if (idbg != 0)
+            {
+                System.Console.WriteLine(" table of ratios \n");
+            }
+
+            for (k = 1; k <= kmaxm2; k++)
+            {
+                for (j = 1; j <= k; j++)
+                {
+                    ratio = 0;
+                    if (System.Math.Abs(t[k + 1][j]) > 0)
+                    {
+                        ratio = t[k][j] / t[k + 1][j];
+                    }
+                    t[k][j] = ratio;
+                }
+            }
+
+            if (idbg != 0)
+            {
+                j = 1;
+                System.Console.WriteLine("{0} {1} {2}\n", t[k][j], j, k);
+            }
+
+        L40:
+            {
+            }
+        }
+
+        return true;
+    }
+
+    private static double F(double x)
+    {
+        return (System.Math.Exp((-(x)) * (x)));
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Romber/Romber.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Romber/Romber.csproj
new file mode 100644 (file)
index 0000000..6094080
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Romber.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Secant/Secant.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Secant/Secant.cs
new file mode 100644 (file)
index 0000000..e7d1ace
--- /dev/null
@@ -0,0 +1,142 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// The secant algorithm adapted from Conte and DeBoor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Secant
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 3000000;
+#endif
+
+    public static volatile object VolatileObject;
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static void Escape(object obj)
+    {
+        VolatileObject = obj;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        int idbg, iflag;
+        double x0, x1, fx1;
+
+        iflag = 0;
+        idbg = 0;
+        x1 = 0;
+        fx1 = 0.0;
+
+        for (int i = 1; i <= Iterations; i++)
+        {
+            x0 = 1.0;
+            x1 = 2.0;
+            Inner(ref x0, ref x1, 0.0000001, 0.0000001, 30, out iflag);
+            if (iflag > 1)
+            {
+                goto L888;
+            }
+
+            fx1 = FF(x1);
+            if (idbg != 0)
+            {
+                System.Console.WriteLine(" the root is {0:E}, F(ROOT):= {1:E}\n", x1, fx1);
+            }
+        L888:
+            {
+            }
+        }
+
+        // Escape iflag, x1, and fx1 so that they appear live
+        Escape(iflag);
+        Escape(x1);
+        Escape(fx1);
+
+        return true;
+    }
+
+    private static double FF(double x)
+    {
+        return (-1.0 - (x * (1.0 - (x * x))));
+    }
+
+    private static void Inner(ref double x0, ref double x1, double xtol, double ftol, int ntol, out int iflag)
+    {
+        double deltax, deltaf, f0, f1;
+
+        iflag = 0;
+        f0 = FF(x0);
+        deltax = x1 - x0;
+
+        for (int n = 1; n <= ntol; n++)
+        {
+            f1 = FF(x1);
+
+            if (System.Math.Abs(f1) <= ftol)
+            {
+                goto L30;
+            }
+
+            deltaf = f0 - f1;
+            if (deltaf == 0.0)
+            {
+                goto L999;
+            }
+
+            deltax = f1 / deltaf * deltax;
+            x0 = x1;
+            x1 = x1 + deltax;
+            if (System.Math.Abs(deltax) <= xtol)
+            {
+                goto L88;
+            }
+
+            f0 = f1;
+        }
+
+    L999:
+        iflag = 2;
+        goto L88;
+    L30:
+        iflag = 1;
+    L88:
+        {
+        }
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Secant/Secant.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Secant/Secant.csproj
new file mode 100644 (file)
index 0000000..f0797ff
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Secant.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Simpsn/Simpsn.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Simpsn/Simpsn.cs
new file mode 100644 (file)
index 0000000..e1e9f0e
--- /dev/null
@@ -0,0 +1,93 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// Integration by Simpson's rule adapted from Conte and de Boor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Simpsn
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 90000;
+#endif
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double a, b, x, s, c, h, hov2, half, t1;
+        int idbg, n, nm1;
+
+        s = 0;
+        idbg = 0;
+        if (idbg != 0)
+        {
+            System.Console.WriteLine("simpsons rule\n");
+        }
+
+        for (int j = 1; j <= Iterations; j++)
+        {
+            a = 0;
+            b = 1;
+            c = 4;
+            n = 100;
+            h = (b - a) / n;
+            hov2 = h / System.Math.Sqrt(c);
+            s = 0;
+            t1 = a + hov2;
+            half = F(t1);
+            nm1 = n - 1;
+            for (int i = 1; i <= nm1; i++)
+            {
+                x = a + i * h;
+                s = s + F(x);
+                t1 = x + hov2;
+                half = half + F(t1);
+                s = (h / 6) * (F(a) + 4 * half + 2 * s + F(b));
+                if (idbg != 0)
+                {
+                    System.Console.WriteLine(" integral from a = {0} to b = {1} for n = {2} is {3}\n", a, b, n, s);
+                }
+            }
+        }
+
+        return true;
+    }
+
+    private static double F(double x)
+    {
+        return (System.Math.Exp((-(x)) * 2));
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Simpsn/Simpsn.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Simpsn/Simpsn.csproj
new file mode 100644 (file)
index 0000000..d3a04a6
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Simpsn.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
index a35ba8b..673757c 100644 (file)
@@ -13,55 +13,64 @@ using Xunit;
 
 public static class SqMtx
 {
-
 #if DEBUG
     public const int Iterations = 1;
 #else
     public const int Iterations = 4000;
 #endif
 
-    const int MatrixSize = 40;
+    private const int MatrixSize = 40;
 
-    static T[][] AllocArray<T>(int n1, int n2) {
+    private static T[][] AllocArray<T>(int n1, int n2)
+    {
         T[][] a = new T[n1][];
-        for (int i = 0; i < n1; ++i) {
+        for (int i = 0; i < n1; ++i)
+        {
             a[i] = new T[n2];
         }
         return a;
     }
 
     [MethodImpl(MethodImplOptions.NoInlining)]
-    static bool Bench()
+    private static bool Bench()
     {
         double[][] a = AllocArray<double>(41, 41);
         double[][] c = AllocArray<double>(41, 41);
-            
+
         int i, j;
 
-        for (i = 1; i <= MatrixSize; i++) {
-            for (j = 1; j <= MatrixSize; j++) {
-               a[i][j] = i + j;
+        for (i = 1; i <= MatrixSize; i++)
+        {
+            for (j = 1; j <= MatrixSize; j++)
+            {
+                a[i][j] = i + j;
             }
         }
 
-        for (i = 1; i <= Iterations; i++) {
+        for (i = 1; i <= Iterations; i++)
+        {
             Inner(a, c, MatrixSize);
         }
 
-        if (c[1][1] == 23820.0) {
+        if (c[1][1] == 23820.0)
+        {
             return true;
         }
-        else {
+        else
+        {
             return false;
         }
     }
 
-    static void Inner(double[][] a, double[][] c, int n)
+    private static void Inner(double[][] a, double[][] c, int n)
     {
-        for (int i = 1; i <= n; i++) {
-            for (int j = 1; j <= n; j++) {
+        for (int i = 1; i <= n; i++)
+        {
+            for (int j = 1; j <= n; j++)
+            {
                 c[i][j] = 0.0;
-                for (int k = 1; k <= n; k++) {
+                for (int k = 1; k <= n; k++)
+                {
                     c[i][j] = c[i][j] + a[i][k] * a[k][j];
                 }
             }
@@ -69,22 +78,26 @@ public static class SqMtx
     }
 
     [Benchmark]
-    public static void Test() {
-        foreach (var iteration in Benchmark.Iterations) {
-            using (iteration.StartMeasurement()) {
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
                 Bench();
             }
         }
     }
 
-    static bool TestBase() {
+    private static bool TestBase()
+    {
         bool result = Bench();
         return result;
     }
 
-    public static int Main() {
+    public static int Main()
+    {
         bool result = TestBase();
         return (result ? 100 : -1);
     }
-
 }
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Trap/Trap.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Trap/Trap.cs
new file mode 100644 (file)
index 0000000..a5e3e5c
--- /dev/null
@@ -0,0 +1,96 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// Integration by corrected trapezoid rule adapted from Conte and de Boor
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Trap
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 240000;
+#endif
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        int nm1, idbg;
+        double t2, cortrp, trap, a, b, h;
+        trap = 0.0;
+        cortrp = 0.0;
+
+        idbg = 0;
+        for (int j = 1; j <= Iterations; j++)
+        {
+            a = 0;
+            b = 1;
+            if (idbg != 0)
+            {
+                System.Console.WriteLine("trapazoid sum    corr.trap sum \n");
+            }
+
+            for (int n = 10; n <= 15; n++)
+            {
+                h = (b - a) / n;
+                nm1 = n - 1;
+                trap = (F(a) + F(b)) / 2;
+                for (int i = 1; i <= nm1; i++)
+                {
+                    t2 = a + i * h;
+                    trap = trap + F(t2);
+                }
+                trap = trap * h;
+                cortrp = trap + h * h * (FPrime(a) - FPrime(b)) / 12;
+                if (idbg != 0)
+                {
+                    System.Console.WriteLine("{0}, {1}, {2}\n", n, trap, cortrp);
+                }
+            }
+        }
+
+        return true;
+    }
+
+    private static double F(double x)
+    {
+        return (System.Math.Exp(-(x) * (x)));
+    }
+
+    private static double FPrime(double x)
+    {
+        return ((-2) * (x) * (F(x)));
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Trap/Trap.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Trap/Trap.csproj
new file mode 100644 (file)
index 0000000..70ecc3a
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Trap.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Whetsto/Whetsto.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/Whetsto/Whetsto.cs
new file mode 100644 (file)
index 0000000..2ab0b61
--- /dev/null
@@ -0,0 +1,242 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// C# translation of Whetstone Double Precision Benchmark
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class Whetsto
+{
+#if DEBUG
+    public const int Iterations = 1;
+#else
+    public const int Iterations = 50000;
+#endif
+
+    private static int s_j, s_k, s_l;
+    private static double s_t, s_t2;
+
+    public static volatile int Volatile_out;
+
+    private static void Escape(int n, int j, int k, double x1, double x2, double x3, double x4)
+    {
+        Volatile_out = n;
+        Volatile_out = j;
+        Volatile_out = k;
+        Volatile_out = (int)x1;
+        Volatile_out = (int)x2;
+        Volatile_out = (int)x3;
+        Volatile_out = (int)x4;
+    }
+
+    [MethodImpl(MethodImplOptions.NoInlining)]
+    private static bool Bench()
+    {
+        double[] e1 = new double[4];
+        double x1, x2, x3, x4, x, y, z, t1;
+        int i, n1, n2, n3, n4, n6, n7, n8, n9, n10, n11;
+
+        s_t = 0.499975;
+        t1 = 0.50025;
+        s_t2 = 2.0;
+        n1 = 0 * Iterations;
+        n2 = 12 * Iterations;
+        n3 = 14 * Iterations;
+        n4 = 345 * Iterations;
+        n6 = 210 * Iterations;
+        n7 = 32 * Iterations;
+        n8 = 899 * Iterations;
+        n9 = 616 * Iterations;
+        n10 = 0 * Iterations;
+        n11 = 93 * Iterations;
+        x1 = 1.0;
+        x2 = x3 = x4 = -1.0;
+
+        for (i = 1; i <= n1; i += 1)
+        {
+            x1 = (x1 + x2 + x3 - x4) * s_t;
+            x2 = (x1 + x2 - x3 - x4) * s_t;
+            x3 = (x1 - x2 + x3 + x4) * s_t;
+            x4 = (-x1 + x2 + x3 + x4) * s_t;
+        }
+        Escape(n1, n1, n1, x1, x2, x3, x4);
+
+        /* MODULE 2:  array elements */
+        e1[0] = 1.0;
+        e1[1] = e1[2] = e1[3] = -1.0;
+        for (i = 1; i <= n2; i += 1)
+        {
+            e1[0] = (e1[0] + e1[1] + e1[2] - e1[3]) * s_t;
+            e1[1] = (e1[0] + e1[1] - e1[2] + e1[3]) * s_t;
+            e1[2] = (e1[0] - e1[1] + e1[2] + e1[3]) * s_t;
+            e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3]) * s_t;
+        }
+        Escape(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
+
+        /* MODULE 3:  array as parameter */
+        for (i = 1; i <= n3; i += 1)
+        {
+            PA(e1);
+        }
+        Escape(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
+
+        /* MODULE 4:  conditional jumps */
+        s_j = 1;
+        for (i = 1; i <= n4; i += 1)
+        {
+            if (s_j == 1)
+            {
+                s_j = 2;
+            }
+            else
+            {
+                s_j = 3;
+            }
+            if (s_j > 2)
+            {
+                s_j = 0;
+            }
+            else
+            {
+                s_j = 1;
+            }
+            if (s_j < 1)
+            {
+                s_j = 1;
+            }
+            else
+            {
+                s_j = 0;
+            }
+        }
+        Escape(n4, s_j, s_j, x1, x2, x3, x4);
+
+        /* MODULE 5:  omitted */
+        /* MODULE 6:  integer Math */
+        s_j = 1;
+        s_k = 2;
+        s_l = 3;
+        for (i = 1; i <= n6; i += 1)
+        {
+            s_j = s_j * (s_k - s_j) * (s_l - s_k);
+            s_k = s_l * s_k - (s_l - s_j) * s_k;
+            s_l = (s_l - s_k) * (s_k + s_j);
+            e1[s_l - 2] = s_j + s_k + s_l;
+            e1[s_k - 2] = s_j * s_k * s_l;
+        }
+        Escape(n6, s_j, s_k, e1[0], e1[1], e1[2], e1[3]);
+
+        /* MODULE 7:  trig. functions */
+        x = y = 0.5;
+        for (i = 1; i <= n7; i += 1)
+        {
+            x = s_t * System.Math.Atan(s_t2 * System.Math.Sin(x) * System.Math.Cos(x) / (System.Math.Cos(x + y) + System.Math.Cos(x - y) - 1.0));
+            y = s_t * System.Math.Atan(s_t2 * System.Math.Sin(y) * System.Math.Cos(y) / (System.Math.Cos(x + y) + System.Math.Cos(x - y) - 1.0));
+        }
+        Escape(n7, s_j, s_k, x, x, y, y);
+
+        /* MODULE 8:  procedure calls */
+        x = y = z = 1.0;
+        for (i = 1; i <= n8; i += 1)
+        {
+            P3(x, y, out z);
+        }
+        Escape(n8, s_j, s_k, x, y, z, z);
+
+        /* MODULE9:  array references */
+        s_j = 1;
+        s_k = 2;
+        s_l = 3;
+        e1[0] = 1.0;
+        e1[1] = 2.0;
+        e1[2] = 3.0;
+        for (i = 1; i <= n9; i += 1)
+        {
+            P0(e1);
+        }
+        Escape(n9, s_j, s_k, e1[0], e1[1], e1[2], e1[3]);
+
+        /* MODULE10:  integer System.Math */
+        s_j = 2;
+        s_k = 3;
+        for (i = 1; i <= n10; i += 1)
+        {
+            s_j = s_j + s_k;
+            s_k = s_j + s_k;
+            s_j = s_k - s_j;
+            s_k = s_k - s_j - s_j;
+        }
+        Escape(n10, s_j, s_k, x1, x2, x3, x4);
+
+        /* MODULE11:  standard functions */
+        x = 0.75;
+        for (i = 1; i <= n11; i += 1)
+        {
+            x = System.Math.Sqrt(System.Math.Exp(System.Math.Log(x) / t1));
+        }
+        Escape(n11, s_j, s_k, x, x, x, x);
+
+        return true;
+    }
+
+    private static void PA(double[] e)
+    {
+        int j;
+        j = 0;
+    lab:
+        e[0] = (e[0] + e[1] + e[2] - e[3]) * s_t;
+        e[1] = (e[0] + e[1] - e[2] + e[3]) * s_t;
+        e[2] = (e[0] - e[1] + e[2] + e[3]) * s_t;
+        e[3] = (-e[0] + e[1] + e[2] + e[3]) / s_t2;
+        j += 1;
+        if (j < 6)
+        {
+            goto lab;
+        }
+    }
+
+    private static void P3(double x, double y, out double z)
+    {
+        x = s_t * (x + y);
+        y = s_t * (x + y);
+        z = (x + y) / s_t2;
+    }
+
+    private static void P0(double[] e1)
+    {
+        e1[s_j] = e1[s_k];
+        e1[s_k] = e1[s_l];
+        e1[s_l] = e1[s_j];
+    }
+
+    [Benchmark]
+    public static void Test()
+    {
+        foreach (var iteration in Benchmark.Iterations)
+        {
+            using (iteration.StartMeasurement())
+            {
+                Bench();
+            }
+        }
+    }
+
+    private static bool TestBase()
+    {
+        bool result = Bench();
+        return result;
+    }
+
+    public static int Main()
+    {
+        bool result = TestBase();
+        return (result ? 100 : -1);
+    }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/Whetsto/Whetsto.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/Whetsto/Whetsto.csproj
new file mode 100644 (file)
index 0000000..c112aa9
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <FileAlignment>512</FileAlignment>
+    <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+    <ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages</ReferencePath>
+    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+    <NuGetPackageImportStamp>7a9bfb7d</NuGetPackageImportStamp>
+    <IlasmRoundTrip>true</IlasmRoundTrip>
+  </PropertyGroup>
+  <!-- Default configurations to help VS understand the configurations -->
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+  </PropertyGroup>
+  <ItemGroup>
+    <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+      <Visible>False</Visible>
+    </CodeAnalysisDependentAssemblyPaths>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="$(JitPackagesConfigFileDirectory)benchmark\project.json" />
+  </ItemGroup>
+  <ItemGroup>
+    <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Whetsto.cs" />
+  </ItemGroup>
+  <PropertyGroup>
+    <ProjectJson>$(JitPackagesConfigFileDirectory)benchmark\project.json</ProjectJson>
+    <ProjectLockJson>$(JitPackagesConfigFileDirectory)benchmark\project.lock.json</ProjectLockJson>
+  </PropertyGroup>
+  <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+  <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' ">
+  </PropertyGroup>
+</Project>