Build-Time Hello World Performance Test (#2681)

Hello world build performance benchmark.
This commit is contained in:
Brian Robbins 2016-04-26 17:52:34 -07:00
parent f420e1478e
commit 705a48940f
6 changed files with 194 additions and 19 deletions

View file

@ -0,0 +1,92 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Xunit.Performance;
using Xunit;
using System.Diagnostics;
namespace Microsoft.DotNet.Tests.Performance
{
public class HelloWorld : TestBase
{
private static readonly string s_testdirName = "helloworldtestroot";
private static readonly string s_outputdirName = "test space/bin";
private static string AssetsRoot { get; set; }
private static string RestoredTestProjectDirectory { get; set; }
private string TestDirectory { get; set; }
private string TestProject { get; set; }
private string OutputDirectory { get; set; }
static HelloWorld()
{
HelloWorld.SetupStaticTestProject();
}
public HelloWorld()
{
}
[Benchmark]
public void MeasureDotNetBuild()
{
foreach (var iter in Benchmark.Iterations)
{
// Setup a new instance of the test project.
TestInstanceSetup();
// Setup the build command.
var buildCommand = new BuildCommand(TestProject, output: OutputDirectory, framework: DefaultFramework);
using (iter.StartMeasurement())
{
// Execute the build command.
buildCommand.Execute();
}
}
}
private void TestInstanceSetup()
{
var root = Temp.CreateDirectory();
var testInstanceDir = root.CopyDirectory(RestoredTestProjectDirectory);
TestDirectory = testInstanceDir.Path;
TestProject = Path.Combine(TestDirectory, "project.json");
OutputDirectory = Path.Combine(TestDirectory, s_outputdirName);
}
private static void SetupStaticTestProject()
{
AssetsRoot = Path.Combine(AppContext.BaseDirectory, "bin");
RestoredTestProjectDirectory = Path.Combine(AssetsRoot, s_testdirName);
// Ignore Delete Failure
try
{
Directory.Delete(RestoredTestProjectDirectory, true);
}
catch (Exception) { }
Directory.CreateDirectory(RestoredTestProjectDirectory);
// Todo: this is a hack until corefx is on nuget.org remove this After RC 2 Release
NuGetConfig.Write(RestoredTestProjectDirectory);
var newCommand = new NewCommand();
newCommand.WorkingDirectory = RestoredTestProjectDirectory;
newCommand.Execute().Should().Pass();
var restoreCommand = new RestoreCommand();
restoreCommand.WorkingDirectory = RestoredTestProjectDirectory;
restoreCommand.Execute("--quiet").Should().Pass();
}
}
}

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>6A3095FF-A7C5-4300-85A9-C025C384401D</ProjectGuid>
<RootNamespace>Microsoft.DotNet.Tests.Performance</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,32 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-*"
},
"System.Runtime.Serialization.Primitives": "4.1.1-rc2-24022",
"Microsoft.DotNet.ProjectModel": {
"target": "project"
},
"Microsoft.DotNet.Cli.Utils": {
"target": "project"
},
"Microsoft.DotNet.Tools.Tests.Utilities": {
"target": "project"
},
"xunit": "2.1.0",
"xunit.netcore.extensions": "1.0.0-prerelease-00206",
"dotnet-test-xunit": "1.0.0-rc2-162081-13",
"Microsoft.DotNet.xunit.performance": "1.0.0-alpha-build0028"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.4",
"portable-net451+win8"
]
}
},
"testRunner": "xunit"
}