summaryrefslogtreecommitdiff
path: root/tests/src/JIT/Performance/CodeQuality/BenchI
diff options
context:
space:
mode:
authorAndy Ayers <andya@microsoft.com>2015-12-02 12:42:11 -0800
committerAndy Ayers <andya@microsoft.com>2015-12-03 16:37:17 -0800
commitbb3877b83748112713cf2fd6234e68f64774363a (patch)
tree7caf71a6ff3bbe9a9f4858cccb4db6d8ce06c353 /tests/src/JIT/Performance/CodeQuality/BenchI
parent2fcc1dd5420572cdec046274156bbd36ee355512 (diff)
downloadcoreclr-bb3877b83748112713cf2fd6234e68f64774363a.tar.gz
coreclr-bb3877b83748112713cf2fd6234e68f64774363a.tar.bz2
coreclr-bb3877b83748112713cf2fd6234e68f64774363a.zip
Initial cut at a jit benchmark using xunit-performance
Provides for standalone execution as well as xunit discovery. I've also created a benchmark project.json for the various benchmarks to share. Add inner iterations to bump per outer-iteration time to around 1 second. Conditionalize iteration count on Debug/Release build type. Also, reduce logging verbosity by default when building tests. Add a "verbose" option to buildtest.cmd to ramp it back up.
Diffstat (limited to 'tests/src/JIT/Performance/CodeQuality/BenchI')
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.cs89
-rw-r--r--tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.csproj45
2 files changed, 134 insertions, 0 deletions
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.cs b/tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.cs
new file mode 100644
index 0000000000..933f931978
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.cs
@@ -0,0 +1,89 @@
+// 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 XposMatrix
+{
+ public const int ArraySize = 100;
+
+#if DEBUG
+ public const int Iterations = 1;
+#else
+ public const int Iterations = 25000;
+#endif
+
+ 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;
+ }
+
+ static void Inner(int[][] x, int n) {
+ for (int i = 1; i <= n; i++) {
+ for (int j = 1; j <= n; j++) {
+ int t = x[i][j];
+ x[i][j] = x[j][i];
+ x[j][i] = t;
+ }
+ }
+ }
+
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ static bool Bench(int[][] matrix) {
+
+ int n = ArraySize;
+ for (int i = 1; i <= n; i++) {
+ for (int j = 1; j <= n; j++) {
+ matrix[i][j] = 1;
+ }
+ }
+
+ if (matrix[n][n] != 1) {
+ return false;
+ }
+
+ Inner(matrix, n);
+
+ if (matrix[n][n] != 1) {
+ return false;
+ }
+
+ return true;
+ }
+
+ [Benchmark]
+ public static void Test() {
+ int[][] matrix = AllocArray<int>(ArraySize + 1, ArraySize + 1);
+ foreach (var iteration in Benchmark.Iterations) {
+ using (iteration.StartMeasurement()) {
+ for (int i = 0; i < Iterations; i++) {
+ Bench(matrix);
+ }
+ }
+ }
+ }
+
+ static bool TestBase() {
+ int[][] matrix = AllocArray<int>(ArraySize + 1, ArraySize + 1);
+ bool result = true;
+ for (int i = 0; i < Iterations; i++) {
+ result &= Bench(matrix);
+ }
+ return result;
+ }
+
+ public static int Main() {
+ bool result = TestBase();
+ return (result ? 100 : -1);
+ }
+}
diff --git a/tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.csproj b/tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.csproj
new file mode 100644
index 0000000000..104a177e55
--- /dev/null
+++ b/tests/src/JIT/Performance/CodeQuality/BenchI/XposMatrix/XposMatrix.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="XposMatrix.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>