summaryrefslogtreecommitdiff
path: root/tests/src
diff options
context:
space:
mode:
authorAndy Ayers <andya@microsoft.com>2016-01-07 23:13:23 -0800
committerAndy Ayers <andya@microsoft.com>2016-01-08 13:42:55 -0800
commit414ab4ee1a6f31ae63f166de2b9d4d0af640574f (patch)
tree43b2681a779ae29d35f07aefba694f2270d831f0 /tests/src
parentf7a10e319c3323f8dcb89172ffee7dda8cfb365f (diff)
downloadcoreclr-414ab4ee1a6f31ae63f166de2b9d4d0af640574f.tar.gz
coreclr-414ab4ee1a6f31ae63f166de2b9d4d0af640574f.tar.bz2
coreclr-414ab4ee1a6f31ae63f166de2b9d4d0af640574f.zip
Add a subset of benchmark game benchmarks
Add tests that are not multithreaded and don't rely on large input files. These are adapted for xunit-performance. Add license and readme.
Diffstat (limited to 'tests/src')
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/LICENSE.TXT18
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/README.TXT37
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csharp.cs148
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csproj45
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fasta/fasta.csharp-2.cs217
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fasta/fasta.csproj45
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fastaredux/fastaredux.csharp.cs181
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fastaredux/fastaredux.csproj45
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/nbody/nbody.csharp-3.cs153
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/nbody/nbody.csproj45
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/pidigits/pi-digits.cs111
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/pidigits/pi-digits.csproj45
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs121
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.csproj45
14 files changed, 1256 insertions, 0 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/LICENSE.TXT b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/LICENSE.TXT
new file mode 100644
index 0000000000..5e0fbafb8d
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/LICENSE.TXT
@@ -0,0 +1,18 @@
+Revised BSD license
+
+This is a specific instance of the Open Source Initiative (OSI) BSD license template
+http://www.opensource.org/licenses/bsd-license.php
+
+
+Copyright © 2004-2008 Brent Fulgham, 2005-2015 Isaac Gouy
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+ Neither the name of "The Computer Language Benchmarks Game" nor the name of "The Computer Language Shootout Benchmarks" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/README.TXT b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/README.TXT
new file mode 100644
index 0000000000..b95d43c361
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/README.TXT
@@ -0,0 +1,37 @@
+The benchmarks in these sub-directories are based on
+
+ The Computer Language Benchmarks Game
+ http://benchmarksgame.alioth.debian.org/
+
+See the adjoining LICENSE.TXT file for license terms.
+
+Our intention with these tests is to provide interesting test cases
+for jit developers to use in daily development practice -- not to
+produce variants that give the maximum possible performance.
+
+The benchmarks have been modified to fit into the CoreCLR test and
+performance test framework, as follows:
+
+ - adding validity checks to ensure optimizers correctly optimize
+ and do not remove computation
+ - adding return codes to main based on those checks
+ - adding an xunit-performance entry point, and adjusting work so each
+ xunit-performance iteration is approximately 1 second on modern x64
+ hardware
+ - reducing verbosity when run as a benchmark
+ - reformatting (via the codeformatter tool)
+
+These benchmarks are just a subset of the benchmarks available in C# from
+the Benchmarks Game site. We've selected variants that do not rely on
+multiple threads to ensure relative benchmark stability across a
+variety of machines.
+
+We've excluded two benchmarks that are inherently multitheaded:
+chamenosredux and threadring. We may revisit this as we improve our
+ability to harness threading tests in a stable way.
+
+We've also excluded benchmarks that read in large input files:
+knucleotide, regexdna, revcomp.
+
+
+
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csharp.cs b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csharp.cs
new file mode 100644
index 0000000000..3e1bdad5ad
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csharp.cs
@@ -0,0 +1,148 @@
+/* The Computer Language Benchmarks Game
+ http://benchmarksgame.alioth.debian.org/
+
+ contributed by Marek Safar
+
+ modified for use with xunit-performance
+*/
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Runtime.CompilerServices;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public class BinaryTrees
+{
+ private const int minDepth = 4;
+ private const int Iterations = 1;
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static bool Bench(bool verbose = false)
+ {
+ int n = 16;
+ int maxDepth = Math.Max(minDepth + 2, n);
+ int stretchDepth = maxDepth + 1;
+ int t = 0;
+
+ int check = (TreeNode.bottomUpTree(0, stretchDepth)).itemCheck();
+ if (verbose)
+ {
+ Console.WriteLine("stretch tree of depth {0}\t check: {1}", stretchDepth, check);
+ }
+ t += check;
+
+ TreeNode longLivedTree = TreeNode.bottomUpTree(0, maxDepth);
+
+ for (int depth = minDepth; depth <= maxDepth; depth += 2)
+ {
+ int iterations = 1 << (maxDepth - depth + minDepth);
+
+ check = 0;
+ for (int i = 1; i <= iterations; i++)
+ {
+ check += (TreeNode.bottomUpTree(i, depth)).itemCheck();
+ check += (TreeNode.bottomUpTree(-i, depth)).itemCheck();
+ }
+
+ if (verbose)
+ {
+ Console.WriteLine("{0}\t trees of depth {1}\t check: {2}",
+ iterations * 2, depth, check);
+ }
+
+ t += check;
+ }
+
+ if (verbose)
+ {
+ Console.WriteLine("long lived tree of depth {0}\t check: {1}",
+ maxDepth, longLivedTree.itemCheck());
+ }
+
+ t += check;
+
+ return (t == -174785);
+ }
+
+ private struct TreeNode
+ {
+ private class Next
+ {
+ public TreeNode left, right;
+ }
+
+ private Next _next;
+ private int _item;
+
+ private TreeNode(int item)
+ {
+ _item = item;
+ _next = null;
+ }
+
+ internal static TreeNode bottomUpTree(int item, int depth)
+ {
+ if (depth > 0)
+ {
+ return new TreeNode(
+ bottomUpTree(2 * item - 1, depth - 1)
+ , bottomUpTree(2 * item, depth - 1)
+ , item
+ );
+ }
+ else
+ {
+ return new TreeNode(item);
+ }
+ }
+
+ private TreeNode(TreeNode left, TreeNode right, int item)
+ {
+ _next = new Next();
+ _next.left = left;
+ _next.right = right;
+ _item = item;
+ }
+
+ internal int itemCheck()
+ {
+ // if necessary deallocate here
+ if (_next == null) return _item;
+ else return _item + _next.left.itemCheck() - _next.right.itemCheck();
+ }
+ }
+
+ [Benchmark]
+ public static void Test()
+ {
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ for (int i = 0; i < Iterations; i++)
+ {
+ Bench();
+ }
+ }
+ }
+ }
+
+ private static bool TestBase()
+ {
+ bool result = true;
+ for (int i = 0; i < Iterations; i++)
+ {
+ result &= Bench(true);
+ }
+ return result;
+ }
+
+ public static int Main()
+ {
+ bool result = TestBase();
+ return (result ? 100 : -1);
+ }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csproj b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csproj
new file mode 100644
index 0000000000..53cd966ce6
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/binarytrees/binarytrees.csproj
@@ -0,0 +1,45 @@
+<?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>
+ </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="binarytrees.csharp.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/BenchmarksGame/fasta/fasta.csharp-2.cs b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fasta/fasta.csharp-2.cs
new file mode 100644
index 0000000000..62e1d05b3a
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fasta/fasta.csharp-2.cs
@@ -0,0 +1,217 @@
+/* The Computer Language Benchmarks Game
+ http://benchmarksgame.alioth.debian.org/
+
+ contributed by Isaac Gouy
+ optimizations by Alp Toker <alp@atoker.com>
+
+ modified for use with xunit-performance
+*/
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.IO;
+using System.Text;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public class Fasta
+{
+#if DEBUG
+ private const int Iterations = 1;
+#else
+ const int Iterations = 800;
+#endif
+
+ public static int Main(string[] args)
+ {
+ MakeCumulative(s_homoSapiens);
+ MakeCumulative(s_IUB);
+
+ int n = args.Length > 0 ? Int32.Parse(args[0]) : 1000;
+
+ using (Stream s = Console.OpenStandardOutput())
+ {
+ MakeRepeatFasta("ONE", "Homo sapiens alu", Encoding.ASCII.GetBytes(s_ALU), n * 2, s);
+ MakeRandomFasta("TWO", "IUB ambiguity codes", s_IUB, n * 3, s);
+ MakeRandomFasta("THREE", "Homo sapiens frequency", s_homoSapiens, n * 5, s);
+ }
+ return 100;
+ }
+
+ [Benchmark]
+ public static void Bench()
+ {
+ int n = 5000;
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ for (int i = 0; i < Iterations; i++)
+ {
+ using (Stream s = Stream.Null)
+ {
+ MakeRepeatFasta("ONE", "Homo sapiens alu", Encoding.ASCII.GetBytes(s_ALU), n * 2, s);
+ MakeRandomFasta("TWO", "IUB ambiguity codes", s_IUB, n * 3, s);
+ MakeRandomFasta("THREE", "Homo sapiens frequency", s_homoSapiens, n * 5, s);
+ }
+ }
+ }
+ }
+ }
+
+ // The usual pseudo-random number generator
+
+ private const int IM = 139968;
+ private const int IA = 3877;
+ private const int IC = 29573;
+ private static int s_seed = 42;
+
+ private static double random(double max)
+ {
+ return max * ((s_seed = (s_seed * IA + IC) % IM) * (1.0 / IM));
+ }
+
+ // Weighted selection from alphabet
+
+ private static string s_ALU =
+ "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
+
+ private class Frequency
+ {
+ public byte c;
+ public double p;
+
+ public Frequency(char c, double p)
+ {
+ this.c = (byte)c;
+ this.p = p;
+ }
+ }
+
+ private static Frequency[] s_IUB = {
+ new Frequency ('a', 0.27)
+ ,new Frequency ('c', 0.12)
+ ,new Frequency ('g', 0.12)
+ ,new Frequency ('t', 0.27)
+
+ ,new Frequency ('B', 0.02)
+ ,new Frequency ('D', 0.02)
+ ,new Frequency ('H', 0.02)
+ ,new Frequency ('K', 0.02)
+ ,new Frequency ('M', 0.02)
+ ,new Frequency ('N', 0.02)
+ ,new Frequency ('R', 0.02)
+ ,new Frequency ('S', 0.02)
+ ,new Frequency ('V', 0.02)
+ ,new Frequency ('W', 0.02)
+ ,new Frequency ('Y', 0.02)
+ };
+
+ private static Frequency[] s_homoSapiens = {
+ new Frequency ('a', 0.3029549426680)
+ ,new Frequency ('c', 0.1979883004921)
+ ,new Frequency ('g', 0.1975473066391)
+ ,new Frequency ('t', 0.3015094502008)
+ };
+
+ private static void MakeCumulative(Frequency[] a)
+ {
+ double cp = 0.0;
+ for (int i = 0; i < a.Length; i++)
+ {
+ cp += a[i].p;
+ a[i].p = cp;
+ }
+ }
+
+ // naive
+ private static byte SelectRandom(Frequency[] a)
+ {
+ double r = random(1.0);
+
+ for (int i = 0; i < a.Length; i++)
+ if (r < a[i].p)
+ return a[i].c;
+
+ return a[a.Length - 1].c;
+ }
+
+ private const int LineLength = 60;
+ private static int s_index = 0;
+ private static byte[] s_buf = new byte[1024];
+
+ private static void MakeRandomFasta(string id, string desc, Frequency[] a, int n, Stream s)
+ {
+ s_index = 0;
+ int m = 0;
+
+ byte[] descStr = Encoding.ASCII.GetBytes(">" + id + " " + desc + "\n");
+ s.Write(descStr, 0, descStr.Length);
+
+ while (n > 0)
+ {
+ m = n < LineLength ? n : LineLength;
+
+ if (s_buf.Length - s_index < m)
+ {
+ s.Write(s_buf, 0, s_index);
+ s_index = 0;
+ }
+
+ for (int i = 0; i < m; i++)
+ {
+ s_buf[s_index++] = SelectRandom(a);
+ }
+
+ s_buf[s_index++] = (byte)'\n';
+ n -= LineLength;
+ }
+
+ if (s_index != 0)
+ s.Write(s_buf, 0, s_index);
+ }
+
+ private static void MakeRepeatFasta(string id, string desc, byte[] alu, int n, Stream s)
+ {
+ s_index = 0;
+ int m = 0;
+ int k = 0;
+ int kn = alu.Length;
+
+ byte[] descStr = Encoding.ASCII.GetBytes(">" + id + " " + desc + "\n");
+ s.Write(descStr, 0, descStr.Length);
+
+ while (n > 0)
+ {
+ m = n < LineLength ? n : LineLength;
+
+ if (s_buf.Length - s_index < m)
+ {
+ s.Write(s_buf, 0, s_index);
+ s_index = 0;
+ }
+
+ for (int i = 0; i < m; i++)
+ {
+ if (k == kn)
+ k = 0;
+
+ s_buf[s_index++] = alu[k];
+ k++;
+ }
+
+ s_buf[s_index++] = (byte)'\n';
+ n -= LineLength;
+ }
+
+ if (s_index != 0)
+ s.Write(s_buf, 0, s_index);
+ }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fasta/fasta.csproj b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fasta/fasta.csproj
new file mode 100644
index 0000000000..8747ba28ee
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fasta/fasta.csproj
@@ -0,0 +1,45 @@
+<?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>
+ </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="fasta.csharp-2.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/BenchmarksGame/fastaredux/fastaredux.csharp.cs b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fastaredux/fastaredux.csharp.cs
new file mode 100644
index 0000000000..b3cdb551b2
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fastaredux/fastaredux.csharp.cs
@@ -0,0 +1,181 @@
+/* The Computer Language Benchmarks Game
+ http://benchmarksgame.alioth.debian.org/
+
+ contributed by Robert F. Tobler
+ optimized based on java & C# by Enotus, Isaac Gouy, and Alp Toker
+
+ modified for use with xunit-performance
+*/
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.IO;
+using System.Text;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public static class FastaRedux
+{
+#if DEBUG
+ private const int Iterations = 1;
+#else
+ const int Iterations = 5;
+#endif
+
+ public static int Main(string[] args)
+ {
+ AccumulateAndScale(s_homoSapiens);
+ AccumulateAndScale(s_IUB);
+ int n = args.Length > 0 ? Int32.Parse(args[0]) : 2500;
+ using (Stream s = Console.OpenStandardOutput())
+ {
+ s.WriteRepeatFasta("ONE", "Homo sapiens alu", Encoding.ASCII.GetBytes(s_ALU), n * 2);
+ s.WriteRandomFasta("TWO", "IUB ambiguity codes", s_IUB, n * 3);
+ s.WriteRandomFasta("THREE", "Homo sapiens frequency", s_homoSapiens, n * 5);
+ }
+ return 100;
+ }
+
+ [Benchmark]
+ public static void Bench()
+ {
+ int n = 2500000;
+ AccumulateAndScale(s_homoSapiens);
+ AccumulateAndScale(s_IUB);
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ using (Stream s = Stream.Null)
+ {
+ for (int i = 0; i < Iterations; i++)
+ {
+ s.WriteRepeatFasta("ONE", "Homo sapiens alu", Encoding.ASCII.GetBytes(s_ALU), n * 2);
+ s.WriteRandomFasta("TWO", "IUB ambiguity codes", s_IUB, n * 3);
+ s.WriteRandomFasta("THREE", "Homo sapiens frequency", s_homoSapiens, n * 5);
+ }
+ }
+ }
+ }
+ }
+
+ private const int LINE_LEN = 60;
+ private const int BUF_LEN = 64 * 1024;
+ private const byte LF = (byte)'\n';
+
+ private const int LOOKUP_LEN = 1024;
+ private const double LOOKUP_SCALE = LOOKUP_LEN - 1;
+
+ private static readonly string s_ALU =
+ "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTGG" +
+ "GAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGAGA" +
+ "CCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAAAAT" +
+ "ACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAATCCCA" +
+ "GCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAACCCGGG" +
+ "AGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTGCACTCC" +
+ "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
+
+ private struct Freq
+ {
+ public double P;
+ public byte C;
+
+ public Freq(char c, double p) { C = (byte)c; P = p; }
+ }
+
+ private static Freq[] s_IUB = {
+ new Freq('a', 0.27), new Freq('c', 0.12), new Freq('g', 0.12),
+ new Freq('t', 0.27), new Freq('B', 0.02), new Freq('D', 0.02),
+ new Freq('H', 0.02), new Freq('K', 0.02), new Freq('M', 0.02),
+ new Freq('N', 0.02), new Freq('R', 0.02), new Freq('S', 0.02),
+ new Freq('V', 0.02), new Freq('W', 0.02), new Freq('Y', 0.02),
+ };
+
+ private static Freq[] s_homoSapiens = {
+ new Freq ('a', 0.3029549426680), new Freq ('c', 0.1979883004921),
+ new Freq ('g', 0.1975473066391), new Freq ('t', 0.3015094502008),
+ };
+
+ private static void AccumulateAndScale(Freq[] a)
+ {
+ double cp = 0.0;
+ for (int i = 0; i < a.Length; i++)
+ a[i].P = (cp += a[i].P) * LOOKUP_SCALE;
+ a[a.Length - 1].P = LOOKUP_SCALE;
+ }
+
+ private static byte[] s_buf = new byte[BUF_LEN];
+
+ private static int WriteDesc(this byte[] buf, string id, string desc)
+ {
+ var ds = Encoding.ASCII.GetBytes(">" + id + " " + desc + "\n");
+ for (int i = 0; i < ds.Length; i++) buf[i] = ds[i];
+ return BUF_LEN - ds.Length;
+ }
+
+ private static int Min(int a, int b) { return a < b ? a : b; }
+
+ private static void WriteRepeatFasta(
+ this Stream s, string id, string desc, byte[] alu, int nr)
+ {
+ int alen = alu.Length;
+ int ar = alen, br = s_buf.WriteDesc(id, desc), lr = LINE_LEN;
+ while (nr > 0)
+ {
+ int r = Min(Min(nr, lr), Min(ar, br));
+ for (int ai = alen - ar, bi = BUF_LEN - br, be = bi + r;
+ bi < be; bi++, ai++)
+ s_buf[bi] = alu[ai];
+ nr -= r; lr -= r; br -= r; ar -= r;
+ if (ar == 0) ar = alen;
+ if (br == 0) { s.Write(s_buf, 0, BUF_LEN); br = BUF_LEN; }
+ if (lr == 0) { s_buf[BUF_LEN - (br--)] = LF; lr = LINE_LEN; }
+ if (br == 0) { s.Write(s_buf, 0, BUF_LEN); br = BUF_LEN; }
+ }
+ if (lr < LINE_LEN) s_buf[BUF_LEN - (br--)] = LF;
+ if (br < BUF_LEN) s.Write(s_buf, 0, BUF_LEN - br);
+ }
+
+ private static Freq[] s_lookup = new Freq[LOOKUP_LEN];
+
+ private static void CreateLookup(Freq[] fr)
+ {
+ for (int i = 0, j = 0; i < LOOKUP_LEN; i++)
+ {
+ while (fr[j].P < i) j++;
+ s_lookup[i] = fr[j];
+ }
+ }
+
+ private const int IM = 139968;
+ private const int IA = 3877;
+ private const int IC = 29573;
+ private const double SCALE = LOOKUP_SCALE / IM;
+
+ private static int s_last = 42;
+
+ private static void WriteRandomFasta(
+ this Stream s, string id, string desc, Freq[] fr, int nr)
+ {
+ CreateLookup(fr);
+ int br = s_buf.WriteDesc(id, desc), lr = LINE_LEN;
+ while (nr > 0)
+ {
+ int r = Min(Min(nr, lr), br);
+ for (int bi = BUF_LEN - br, be = bi + r; bi < be; bi++)
+ {
+ double p = SCALE * (s_last = (s_last * IA + IC) % IM);
+ int ai = (int)p; if (s_lookup[ai].P < p) ai++;
+ s_buf[bi] = s_lookup[ai].C;
+ }
+ nr -= r; lr -= r; br -= r;
+ if (br == 0) { s.Write(s_buf, 0, BUF_LEN); br = BUF_LEN; }
+ if (lr == 0) { s_buf[BUF_LEN - (br--)] = LF; lr = LINE_LEN; }
+ if (br == 0) { s.Write(s_buf, 0, BUF_LEN); br = BUF_LEN; }
+ }
+ if (lr < LINE_LEN) s_buf[BUF_LEN - (br--)] = LF;
+ if (br < BUF_LEN) s.Write(s_buf, 0, BUF_LEN - br);
+ }
+}
+
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fastaredux/fastaredux.csproj b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fastaredux/fastaredux.csproj
new file mode 100644
index 0000000000..d0f74a8559
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/fastaredux/fastaredux.csproj
@@ -0,0 +1,45 @@
+<?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>
+ </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="fastaredux.csharp.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/BenchmarksGame/nbody/nbody.csharp-3.cs b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/nbody/nbody.csharp-3.cs
new file mode 100644
index 0000000000..f9823b1adc
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/nbody/nbody.csharp-3.cs
@@ -0,0 +1,153 @@
+/* The Computer Language Benchmarks Game
+ http://benchmarksgame.alioth.debian.org/
+
+ contributed by Isaac Gouy, optimization and use of more C# idioms by Robert F. Tobler
+
+ modified for use with xunit-performance
+*/
+
+using Microsoft.Xunit.Performance;
+using System;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public class NBody
+{
+ public static int Main(String[] args)
+ {
+ int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000;
+ NBodySystem bodies = new NBodySystem();
+ double initialEnergy = bodies.Energy();
+ Console.WriteLine("{0:f9}", initialEnergy);
+ for (int i = 0; i < n; i++) bodies.Advance(0.01);
+ double finalEnergy = bodies.Energy();
+ Console.WriteLine("{0:f9}", finalEnergy);
+ double deltaEnergy = Math.Abs(initialEnergy - finalEnergy);
+ bool result = deltaEnergy < 1e-4;
+ Console.WriteLine("Energy {0} conserved", result ? "was" : "was not");
+ return (result ? 100 : -1);
+ }
+
+ [Benchmark]
+ public static void Bench()
+ {
+ int n = 5000000;
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ NBodySystem bodies = new NBodySystem();
+ for (int i = 0; i < n; i++) bodies.Advance(0.01);
+ }
+ }
+ }
+}
+
+internal class Body { public double x, y, z, vx, vy, vz, mass; }
+internal class Pair { public Body bi, bj; }
+
+internal class NBodySystem
+{
+ private Body[] _bodies;
+ private Pair[] _pairs;
+
+ private const double Pi = 3.141592653589793;
+ private const double Solarmass = 4 * Pi * Pi;
+ private const double DaysPeryear = 365.24;
+
+ public NBodySystem()
+ {
+ _bodies = new Body[] {
+ new Body() { // Sun
+ mass = Solarmass,
+ },
+ new Body() { // Jupiter
+ x = 4.84143144246472090e+00,
+ y = -1.16032004402742839e+00,
+ z = -1.03622044471123109e-01,
+ vx = 1.66007664274403694e-03 * DaysPeryear,
+ vy = 7.69901118419740425e-03 * DaysPeryear,
+ vz = -6.90460016972063023e-05 * DaysPeryear,
+ mass = 9.54791938424326609e-04 * Solarmass,
+ },
+ new Body() { // Saturn
+ x = 8.34336671824457987e+00,
+ y = 4.12479856412430479e+00,
+ z = -4.03523417114321381e-01,
+ vx = -2.76742510726862411e-03 * DaysPeryear,
+ vy = 4.99852801234917238e-03 * DaysPeryear,
+ vz = 2.30417297573763929e-05 * DaysPeryear,
+ mass = 2.85885980666130812e-04 * Solarmass,
+ },
+ new Body() { // Uranus
+ x = 1.28943695621391310e+01,
+ y = -1.51111514016986312e+01,
+ z = -2.23307578892655734e-01,
+ vx = 2.96460137564761618e-03 * DaysPeryear,
+ vy = 2.37847173959480950e-03 * DaysPeryear,
+ vz = -2.96589568540237556e-05 * DaysPeryear,
+ mass = 4.36624404335156298e-05 * Solarmass,
+ },
+ new Body() { // Neptune
+ x = 1.53796971148509165e+01,
+ y = -2.59193146099879641e+01,
+ z = 1.79258772950371181e-01,
+ vx = 2.68067772490389322e-03 * DaysPeryear,
+ vy = 1.62824170038242295e-03 * DaysPeryear,
+ vz = -9.51592254519715870e-05 * DaysPeryear,
+ mass = 5.15138902046611451e-05 * Solarmass,
+ },
+ };
+
+ _pairs = new Pair[_bodies.Length * (_bodies.Length - 1) / 2];
+ int pi = 0;
+ for (int i = 0; i < _bodies.Length - 1; i++)
+ for (int j = i + 1; j < _bodies.Length; j++)
+ _pairs[pi++] = new Pair() { bi = _bodies[i], bj = _bodies[j] };
+
+ double px = 0.0, py = 0.0, pz = 0.0;
+ foreach (var b in _bodies)
+ {
+ px += b.vx * b.mass; py += b.vy * b.mass; pz += b.vz * b.mass;
+ }
+ var sol = _bodies[0];
+ sol.vx = -px / Solarmass; sol.vy = -py / Solarmass; sol.vz = -pz / Solarmass;
+ }
+
+ public void Advance(double dt)
+ {
+ foreach (var p in _pairs)
+ {
+ Body bi = p.bi, bj = p.bj;
+ double dx = bi.x - bj.x, dy = bi.y - bj.y, dz = bi.z - bj.z;
+ double d2 = dx * dx + dy * dy + dz * dz;
+ double mag = dt / (d2 * Math.Sqrt(d2));
+ bi.vx -= dx * bj.mass * mag; bj.vx += dx * bi.mass * mag;
+ bi.vy -= dy * bj.mass * mag; bj.vy += dy * bi.mass * mag;
+ bi.vz -= dz * bj.mass * mag; bj.vz += dz * bi.mass * mag;
+ }
+ foreach (var b in _bodies)
+ {
+ b.x += dt * b.vx; b.y += dt * b.vy; b.z += dt * b.vz;
+ }
+ }
+
+ public double Energy()
+ {
+ double e = 0.0;
+ for (int i = 0; i < _bodies.Length; i++)
+ {
+ var bi = _bodies[i];
+ e += 0.5 * bi.mass * (bi.vx * bi.vx + bi.vy * bi.vy + bi.vz * bi.vz);
+ for (int j = i + 1; j < _bodies.Length; j++)
+ {
+ var bj = _bodies[j];
+ double dx = bi.x - bj.x, dy = bi.y - bj.y, dz = bi.z - bj.z;
+ e -= (bi.mass * bj.mass) / Math.Sqrt(dx * dx + dy * dy + dz * dz);
+ }
+ }
+ return e;
+ }
+}
+
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/nbody/nbody.csproj b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/nbody/nbody.csproj
new file mode 100644
index 0000000000..5aed1f98c0
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/nbody/nbody.csproj
@@ -0,0 +1,45 @@
+<?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>
+ </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="nbody.csharp-3.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/BenchmarksGame/pidigits/pi-digits.cs b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/pidigits/pi-digits.cs
new file mode 100644
index 0000000000..cc3efc8eaa
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/pidigits/pi-digits.cs
@@ -0,0 +1,111 @@
+/* The Computer Language Benchmarks Game
+ * http://benchmarksgame.alioth.debian.org/
+ *
+ * Port of the C code that uses GMP
+ * Just switched it to use C#'s BigInteger instead
+ *
+ * To compile use csc /o+ /r:System.Numerics.dll
+ *
+ * modified for use with xunit-performance
+*/
+
+using Microsoft.Xunit.Performance;
+using System;
+using System.Numerics;
+using System.Text;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public class pidigits
+{
+#if DEBUG
+ public const int Iterations = 1;
+#else
+ public const int Iterations = 50;
+#endif
+
+ private BigInteger _acc,_den,_num;
+
+ public pidigits()
+ {
+ _acc = BigInteger.Zero;
+ _den = BigInteger.One;
+ _num = BigInteger.One;
+ }
+
+ public uint extract_digit(uint nth)
+ {
+ return (uint)((_num * nth + _acc) / _den);
+ }
+
+ public void eliminate_digit(uint d)
+ {
+ _acc -= _den * d;
+ _acc *= 10;
+ _num *= 10;
+ }
+
+ public void next_term(uint k)
+ {
+ uint k2 = k * 2 + 1;
+ _acc += _num * 2;
+ _acc *= k2;
+ _den *= k2;
+ _num *= k;
+ }
+
+ public void Calculate(int n, bool verbose = false)
+ {
+ StringBuilder sb = new StringBuilder(20);
+ uint d, k, i;
+ for (i = k = 0; i < n;)
+ {
+ next_term(++k);
+ if (_num > _acc)
+ continue;
+ d = extract_digit(3);
+ if (d != extract_digit(4))
+ continue;
+ sb.Append((char)('0' + d));
+ if (++i % 10 == 0)
+ {
+ if (verbose)
+ {
+ Console.WriteLine("{0}\t:{1}", sb, i);
+ }
+ sb.Clear();
+ }
+ eliminate_digit(d);
+ }
+ }
+
+ public static int Main(String[] args)
+ {
+ int length = args.Length == 0 ? 10 : Int32.Parse(args[0]);
+ for (int i = 0; i < Iterations; i++)
+ {
+ pidigits p = new pidigits();
+ p.Calculate(length, true);
+ }
+ return 100;
+ }
+
+ [Benchmark]
+ public static void Bench()
+ {
+ int length = 600;
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ for (int i = 0; i < Iterations; i++)
+ {
+ pidigits p = new pidigits();
+ p.Calculate(length);
+ }
+ }
+ }
+ }
+}
+
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/pidigits/pi-digits.csproj b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/pidigits/pi-digits.csproj
new file mode 100644
index 0000000000..f35733600d
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/pidigits/pi-digits.csproj
@@ -0,0 +1,45 @@
+<?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>
+ </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="pi-digits.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/BenchmarksGame/spectralnorm/spectralnorm.cs b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs
new file mode 100644
index 0000000000..01f5031471
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.cs
@@ -0,0 +1,121 @@
+/* The Computer Language Benchmarks Game
+ http://benchmarksgame.alioth.debian.org/
+
+ contributed by Isaac Gouy
+
+ modified for use with xunit-performance
+*/
+
+using Microsoft.Xunit.Performance;
+using System;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+public class SpectralNorm
+{
+#if DEBUG
+ public const int Iterations = 1;
+#else
+ public const int Iterations = 300;
+#endif
+
+ public static int Main(String[] args)
+ {
+ int n = 100;
+ if (args.Length > 0) n = Int32.Parse(args[0]);
+ double norm = new SpectralNorm().Approximate(n);
+ Console.WriteLine("Norm={0:f9}", norm);
+ double expected = 1.274219991;
+ bool result = Math.Abs(norm - expected) < 1e-4;
+ return (result ? 100 : -1);
+ }
+
+ [Benchmark]
+ public static void Bench()
+ {
+ int n = 100;
+ double a = 0;
+ foreach (var iteration in Benchmark.Iterations)
+ {
+ using (iteration.StartMeasurement())
+ {
+ for (int i = 0; i < Iterations; i++)
+ {
+ SpectralNorm s = new SpectralNorm();
+ a += s.Approximate(n);
+ }
+ }
+ }
+ double norm = a / (n * Iterations);
+ double expected = 1.274219991;
+ bool valid = Math.Abs(norm - expected) < 1e-4;
+ if (!valid)
+ {
+ throw new Exception("Benchmark failed to validate");
+ }
+ }
+
+ private double Approximate(int n)
+ {
+ // create unit vector
+ double[] u = new double[n];
+ for (int i = 0; i < n; i++) u[i] = 1;
+
+ // 20 steps of the power method
+ double[] v = new double[n];
+ for (int i = 0; i < n; i++) v[i] = 0;
+
+ for (int i = 0; i < 10; i++)
+ {
+ MultiplyAtAv(n, u, v);
+ MultiplyAtAv(n, v, u);
+ }
+
+ // B=AtA A multiplied by A transposed
+ // v.Bv /(v.v) eigenvalue of v
+ double vBv = 0, vv = 0;
+ for (int i = 0; i < n; i++)
+ {
+ vBv += u[i] * v[i];
+ vv += v[i] * v[i];
+ }
+
+ return Math.Sqrt(vBv / vv);
+ }
+
+
+ /* return element i,j of infinite matrix A */
+ private double A(int i, int j)
+ {
+ return 1.0 / ((i + j) * (i + j + 1) / 2 + i + 1);
+ }
+
+ /* multiply vector v by matrix A */
+ private void MultiplyAv(int n, double[] v, double[] Av)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ Av[i] = 0;
+ for (int j = 0; j < n; j++) Av[i] += A(i, j) * v[j];
+ }
+ }
+
+ /* multiply vector v by matrix A transposed */
+ private void MultiplyAtv(int n, double[] v, double[] Atv)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ Atv[i] = 0;
+ for (int j = 0; j < n; j++) Atv[i] += A(j, i) * v[j];
+ }
+ }
+
+ /* multiply vector v by matrix A and then by matrix A transposed */
+ private void MultiplyAtAv(int n, double[] v, double[] AtAv)
+ {
+ double[] u = new double[n];
+ MultiplyAv(n, v, u);
+ MultiplyAtv(n, u, AtAv);
+ }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.csproj b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.csproj
new file mode 100644
index 0000000000..a6dc7737ac
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchmarksGame/spectralnorm/spectralnorm.csproj
@@ -0,0 +1,45 @@
+<?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>
+ </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="spectralnorm.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>