summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndy Ayers <andya@microsoft.com>2015-12-08 16:14:49 -0800
committerAndy Ayers <andya@microsoft.com>2015-12-08 16:14:49 -0800
commitc339949d5c69ff7b4e0d79514ae93b66c63769a2 (patch)
tree203083f6014fba7e080bb6a538ffd46c7d8ecd61 /tests
parentd1633211ee01ed05f467cacd36418f313e7a3d71 (diff)
parente6e5a4841e07af76154114fd8391bfbdaceafbea (diff)
downloadcoreclr-c339949d5c69ff7b4e0d79514ae93b66c63769a2.tar.gz
coreclr-c339949d5c69ff7b4e0d79514ae93b66c63769a2.tar.bz2
coreclr-c339949d5c69ff7b4e0d79514ae93b66c63769a2.zip
Merge pull request #2268 from AndyAyersMS/FractalPerf
Add FractalPerf benchmark
Diffstat (limited to 'tests')
-rw-r--r--tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.cs176
-rw-r--r--tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.csproj45
2 files changed, 221 insertions, 0 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.cs b/tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.cs
new file mode 100644
index 0000000000..9d9f36095e
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.cs
@@ -0,0 +1,176 @@
+// 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.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using Xunit;
+
+[assembly: OptimizeForBenchmarks]
+[assembly: MeasureInstructionsRetired]
+
+namespace FractalPerf
+{
+ struct complex
+ {
+ public complex(double a, double b) { r = a; i = b; }
+ public double r;
+ public double i;
+
+ public complex square() {
+ return new complex(r * r - i * i, 2.0 * r * i);
+ }
+
+ public double sqabs() {
+ return r * r + i * i;
+ }
+
+ public override string ToString() {
+ return String.Format("[{0} + {1}i]", r, i);
+ }
+
+ public static complex operator +(complex a, complex b) {
+ return new complex(a.r + b.r, a.i + b.i);
+ }
+ }
+
+ public abstract class Fractal
+ {
+ protected double XB, YB, XE, YE, XS, YS;
+ const double resolution = 375.0;
+
+ public Fractal(double xbeg, double ybeg, double xend, double yend) {
+ XB = Math.Min(xbeg, xend);
+ YB = Math.Min(ybeg, yend);
+ XE = Math.Max(xbeg, xend);
+ YE = Math.Max(ybeg, yend);
+ XS = (xend - xbeg) / resolution;
+ YS = (yend - ybeg) / resolution;
+ }
+
+ public abstract double Render();
+
+ public static double Clamp(double val, double lo, double hi) {
+ return Math.Min(Math.Max(val, lo), hi);
+ }
+ }
+
+ public class Mandelbrot : Fractal
+ {
+ public Mandelbrot() : base(-2.0, -1.5, 1.0, 1.5) { }
+
+ public override double Render() {
+ double limit = 4.0;
+ double result = 0.0;
+
+ for (double y = YB; y < YE; y += YS) {
+ for (double x = YB; x < YE; x += XS) {
+ complex num = new complex(x, y);
+ complex accum = num;
+ int iters;
+ for (iters = 0; iters < 1000; iters++) {
+ accum = accum.square();
+ accum += num;
+ if (accum.sqabs() > limit)
+ break;
+ }
+ result += iters;
+ }
+ }
+ return result;
+ }
+ }
+
+ public class Julia : Fractal
+ {
+ private double Real;
+ double Imaginary;
+ public Julia(double real, double imaginary)
+ : base(-2.0, -1.5, 1.0, 1.5) {
+ Real = real;
+ Imaginary = imaginary;
+ }
+
+ public override double Render() {
+ double limit = 4.0;
+ double result = 0.0;
+
+ // set the Julia Set constant
+ complex seed = new complex(Real, Imaginary);
+ // run through every point on the screen, setting
+ // m and n to the coordinates
+ for (double m = XB; m < XE; m += XS) {
+ for (double n = YB; n < YE; n += YS) {
+ // the initial z value is the current pixel,
+ // so x and y have to be set to m and n
+ complex accum = new complex(m, n);
+ // perform the iteration
+ int num;
+ for (num = 0; num < 1000; num++) {
+ // exit the loop if the number becomes too big
+ if (accum.sqabs() > limit)
+ break;
+ // use the formula
+ accum = accum.square() + seed;
+ }
+ // determine the color using the number of
+ // iterations it took for the number to become too big
+ // char color = num % number_of_colors;
+ // plot the point
+ result += num;
+ }
+ }
+ return result;
+ }
+ }
+
+ public class Launch
+ {
+
+#if DEBUG
+ public const int Iterations = 1;
+#else
+ public const int Iterations = 5;
+#endif
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ static bool Bench()
+ {
+ Mandelbrot m = new Mandelbrot();
+ Julia j = new Julia(-0.62, 0.41);
+ double mResult = m.Render();
+ double jResult = j.Render();
+
+ return true;
+ }
+
+ [Benchmark]
+ public static void Test() {
+ foreach (var iteration in Benchmark.Iterations) {
+ using (iteration.StartMeasurement()) {
+ for (int i = 0; i < Iterations; i++) {
+ Bench();
+ }
+ }
+ }
+ }
+
+ static bool TestBase() {
+ bool result = true;
+ for (int i = 0; i < Iterations; i++) {
+ result &= Bench();
+ }
+ return result;
+ }
+
+ public static int Main() {
+ bool result = TestBase();
+ return (result ? 100 : -1);
+ }
+ }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.csproj b/tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.csproj
new file mode 100644
index 0000000000..a05c92fba6
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/FractalPerf/FractalPerf.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="FractalPerf.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>