2016-05-12 17:33:32 +00:00
|
|
|
|
// 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.Linq;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Microsoft.Xunit.Performance;
|
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Builder.Tests
|
|
|
|
|
{
|
|
|
|
|
public class BuildPerformanceTest : TestBase
|
|
|
|
|
{
|
|
|
|
|
private static string SingleTargetApp = "SingleTargetApp";
|
|
|
|
|
private static string TwoTargetApp = "TwoTargetApp";
|
|
|
|
|
|
|
|
|
|
private static string[] SingleTargetGraph = new[]
|
|
|
|
|
{
|
|
|
|
|
"SingleTargetGraph/SingleTargetP0",
|
|
|
|
|
"SingleTargetGraph/SingleTargetP1",
|
|
|
|
|
"SingleTargetGraph/SingleTargetP2"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string[] TwoTargetGraph = new[]
|
|
|
|
|
{
|
|
|
|
|
"TwoTargetGraph/TwoTargetP0",
|
|
|
|
|
"TwoTargetGraph/TwoTargetP1",
|
|
|
|
|
"TwoTargetGraph/TwoTargetP2"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static string[] TwoTargetGraphLarge = new[]
|
|
|
|
|
{
|
|
|
|
|
"TwoTargetGraphLarge/TwoTargetLargeP0",
|
|
|
|
|
"TwoTargetGraphLarge/TwoTargetLargeP1",
|
|
|
|
|
"TwoTargetGraphLarge/TwoTargetLargeP2",
|
|
|
|
|
"TwoTargetGraphLarge/TwoTargetLargeP3",
|
|
|
|
|
"TwoTargetGraphLarge/TwoTargetLargeP4",
|
|
|
|
|
"TwoTargetGraphLarge/TwoTargetLargeP5",
|
|
|
|
|
"TwoTargetGraphLarge/TwoTargetLargeP6"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildSingleProject_SingleTargetApp() => BuildSingleProject(CreateTestInstance(SingleTargetApp));
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildSingleProject_TwoTargetApp() => BuildSingleProject(CreateTestInstance(TwoTargetApp));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void BuildSingleProject(TestAssetInstance instance)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root);
|
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
buildCommand.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
TouchSource(instance.Root);
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipSingleProject_SingleTargetApp() => IncrementalSkipSingleProject(CreateTestInstance(SingleTargetApp));
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipSingleProject_TwoTargetApp() => IncrementalSkipSingleProject(CreateTestInstance(TwoTargetApp));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void IncrementalSkipSingleProject(TestAssetInstance instance)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root);
|
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
buildCommand
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildAllInGraph_SingleTargetGraph() => BuildAllInGraph(CreateTestInstances(SingleTargetGraph));
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildAllInGraph_TwoTargetGraph() => BuildAllInGraph(CreateTestInstances(TwoTargetGraph));
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildAllInGraph_TwoTargetGraphLarge() => BuildAllInGraph(CreateTestInstances(TwoTargetGraphLarge));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void BuildAllInGraph(TestAssetInstance[] instances)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
var instance = instances[0];
|
|
|
|
|
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root);
|
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
buildCommand
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
foreach (var i in instances)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
TouchSource(i.Root);
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipAllInGraph_SingleTargetGraph() =>
|
|
|
|
|
IncrementalSkipAllInGraph(CreateTestInstances(SingleTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipAllInGraph_TwoTargetGraph() =>
|
|
|
|
|
IncrementalSkipAllInGraph(CreateTestInstances(TwoTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipAllInGraphh_TwoTargetGraphLarge() =>
|
|
|
|
|
IncrementalSkipAllInGraph(CreateTestInstances(TwoTargetGraphLarge));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void IncrementalSkipAllInGraph(TestAssetInstance[] instances)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
var instance = instances[0];
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root);
|
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
buildCommand
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalRebuildWithRootChangedInGraph_SingleTargetGraph() =>
|
|
|
|
|
IncrementalRebuildWithRootChangedInGraph(CreateTestInstances(SingleTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalRebuildWithRootChangedInGraph_TwoTargetGraph() =>
|
|
|
|
|
IncrementalRebuildWithRootChangedInGraph(CreateTestInstances(TwoTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalRebuildWithRootChangedInGraph_TwoTargetGraphLarge() =>
|
|
|
|
|
IncrementalRebuildWithRootChangedInGraph(CreateTestInstances(TwoTargetGraphLarge));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void IncrementalRebuildWithRootChangedInGraph(TestAssetInstance[] instances)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
var instance = instances[0];
|
2016-10-28 01:46:43 +00:00
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root);
|
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
buildCommand
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
TouchSource(instance.Root);
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalRebuildWithLastChangedInGraph_SingleTargetGraph() =>
|
|
|
|
|
IncrementalRebuildWithLastChangedInGraph(CreateTestInstances(SingleTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalRebuildWithLastChangedInGraph_TwoTargetGraph() =>
|
|
|
|
|
IncrementalRebuildWithLastChangedInGraph(CreateTestInstances(TwoTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalRebuildWithLastChangedInGraph_TwoTargetGraphLarge() =>
|
|
|
|
|
IncrementalRebuildWithLastChangedInGraph(CreateTestInstances(TwoTargetGraphLarge));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void IncrementalRebuildWithLastChangedInGraph(TestAssetInstance[] instances)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
var instance = instances[0];
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root);
|
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
buildCommand
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
TouchSource(instances.Last().Root);
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipAllNoDependenciesInGraph_SingleTargetGraph() =>
|
|
|
|
|
IncrementalSkipAllNoDependenciesInGraph(CreateTestInstances(SingleTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipAllNoDependenciesInGraph_TwoTargetGraph() =>
|
|
|
|
|
IncrementalSkipAllNoDependenciesInGraph(CreateTestInstances(TwoTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void IncrementalSkipAllNoDependenciesInGraph_TwoTargetGraphLarge() =>
|
|
|
|
|
IncrementalSkipAllNoDependenciesInGraph(CreateTestInstances(TwoTargetGraphLarge));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void IncrementalSkipAllNoDependenciesInGraph(TestAssetInstance[] instances)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
var instance = instances[0];
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
|
|
|
|
var commands = new List<BuildCommand>();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
foreach (var i in instances.Reverse())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(instance.Root)
|
|
|
|
|
.WithFramework(NuGet.Frameworks.FrameworkConstants.CommonFrameworks.NetCoreApp10)
|
|
|
|
|
.WithNoDependencies();
|
|
|
|
|
|
|
|
|
|
commands.Add(buildCommand);
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
|
|
|
|
foreach (var buildCommand in commands)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
buildCommand
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildAllNoDependenciesInGraph_SingleTargetGraph() =>
|
|
|
|
|
BuildAllNoDependenciesInGraph(CreateTestInstances(SingleTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildAllNoDependenciesInGraph_TwoTargetGraph() =>
|
|
|
|
|
BuildAllNoDependenciesInGraph(CreateTestInstances(TwoTargetGraph));
|
|
|
|
|
|
|
|
|
|
[Benchmark]
|
|
|
|
|
public void BuildAllNoDependenciesInGraph_TwoTargetGraphLarge() =>
|
|
|
|
|
BuildAllNoDependenciesInGraph(CreateTestInstances(TwoTargetGraphLarge));
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
public void BuildAllNoDependenciesInGraph(TestAssetInstance[] instances)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var iteration in Benchmark.Iterations)
|
|
|
|
|
{
|
|
|
|
|
var commands = new List<BuildCommand>();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
foreach (var i in instances.Reverse())
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
|
.WithProjectDirectory(i.Root)
|
|
|
|
|
.WithFramework(NuGet.Frameworks.FrameworkConstants.CommonFrameworks.NetCoreApp10)
|
|
|
|
|
.WithNoDependencies();
|
|
|
|
|
|
|
|
|
|
commands.Add(buildCommand);
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
using (iteration.StartMeasurement())
|
|
|
|
|
{
|
|
|
|
|
foreach (var buildCommand in commands)
|
|
|
|
|
{
|
|
|
|
|
buildCommand.Execute().Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
foreach (var instance in instances)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
TouchSource(instance.Root);
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
protected void TouchSource(DirectoryInfo projectDir)
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var sourceFile = projectDir.GetFiles("*.cs", SearchOption.AllDirectories).FirstOrDefault();
|
|
|
|
|
|
2016-05-12 17:33:32 +00:00
|
|
|
|
if (sourceFile == null)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
throw new InvalidOperationException($"'.cs' files not found in {projectDir.FullName}");
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
sourceFile.LastWriteTime = DateTime.Now;
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
protected TestAssetInstance[] CreateTestInstances(string[] testProjectNames, [CallerMemberName] string callingMethod = "")
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
|
|
|
|
return testProjectNames.Select(testProjectName =>
|
|
|
|
|
{
|
|
|
|
|
return CreateTestInstance(testProjectName, callingMethod);
|
|
|
|
|
}).ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
protected TestAssetInstance CreateTestInstance(string testProjectName, [CallerMemberName] string callingMethod = "")
|
2016-05-12 17:33:32 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
return TestAssets.Get(Path.Combine("PerformanceTestProjects", testProjectName))
|
|
|
|
|
.CreateInstance(callingMethod)
|
|
|
|
|
.WithSourceFiles()
|
|
|
|
|
.WithRestoreFiles();
|
2016-05-12 17:33:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|