diff options
author | Chris McKinsey <chrismck@microsoft.com> | 2015-12-16 15:59:27 -0800 |
---|---|---|
committer | Chris McKinsey <chrismck@microsoft.com> | 2015-12-16 15:59:27 -0800 |
commit | 00449cf210d57ea42c84f72114bc03c248ef057d (patch) | |
tree | ea9e3a0f8c804c0870e905e6a2a2998420496475 /tests/src/JIT/Performance/CodeQuality/BenchF | |
parent | a5e98990f855e72e06ce4e5177e8608c22e2c919 (diff) | |
download | coreclr-00449cf210d57ea42c84f72114bc03c248ef057d.tar.gz coreclr-00449cf210d57ea42c84f72114bc03c248ef057d.tar.bz2 coreclr-00449cf210d57ea42c84f72114bc03c248ef057d.zip |
Add the BenchF/Dmath Benchstone benchmark in the Xunit.performance format.
Diffstat (limited to 'tests/src/JIT/Performance/CodeQuality/BenchF')
-rw-r--r-- | tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.cs | 102 | ||||
-rw-r--r-- | tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.csproj | 45 |
2 files changed, 147 insertions, 0 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.cs b/tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.cs new file mode 100644 index 0000000000..b90127b874 --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.cs @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using Microsoft.Xunit.Performance; +using System; +using System.Runtime.CompilerServices; +using Xunit; + +[assembly: OptimizeForBenchmarks] +[assembly: MeasureInstructionsRetired] + +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; + + static void Escape(object obj) { + VolatileObject = obj; + } + + static double Fact(double n) + { + double res; + res = 1.0; + while (n > 0.0) { + res *= n; + n -= 1.0; + } + + return res; + } + + static double Power(double n, double p) + { + double res; + res = 1.0; + while (p > 0.0) { + res *= n; + p -= 1.0; + } + + return res; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + 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; + } + + [Benchmark] + public static void Test() { + foreach (var iteration in Benchmark.Iterations) { + using (iteration.StartMeasurement()) { + Bench(Iterations); + } + } + } + + static bool TestBase() { + bool result = Bench(Iterations); + return result; + } + + public static int Main() { + bool result = TestBase(); + return (result ? 100 : -1); + } +} + diff --git a/tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.csproj b/tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.csproj new file mode 100644 index 0000000000..a8e767d05e --- /dev/null +++ b/tests/src/JIT/Performance/CodeQuality/BenchF/DMath/DMath.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="DMath.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> |