Skip to content

Commit

Permalink
Adds performance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Apr 12, 2024
1 parent 48d6c1d commit d85ddf9
Show file tree
Hide file tree
Showing 15 changed files with 224 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .run/Generator.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generator" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/build/bin/roslyn4.3/Debug/net8.0/build.exe" />
<option name="EXE_PATH" value="$PROJECT_DIR$/build/bin/Debug/net8.0/build.exe" />
<option name="PROGRAM_PARAMETERS" value="-p:version=2.1.0-dev generator" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PASS_PARENT_ENVS" value="1" />
Expand Down
20 changes: 20 additions & 0 deletions .run/Performance Tests.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Performance Tests" type="DotNetProject" factoryName=".NET Project">
<option name="EXE_PATH" value="$PROJECT_DIR$/build/bin/Debug/net8.0/build.exe" />
<option name="PROGRAM_PARAMETERS" value="perf" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="PASS_PARENT_ENVS" value="1" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="PROJECT_PATH" value="$PROJECT_DIR$/build/build.csproj" />
<option name="PROJECT_EXE_PATH_TRACKING" value="1" />
<option name="PROJECT_ARGUMENTS_TRACKING" value="1" />
<option name="PROJECT_WORKING_DIRECTORY_TRACKING" value="0" />
<option name="PROJECT_KIND" value="DotNetCore" />
<option name="PROJECT_TFM" value="net8.0" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<Product>$(BasePackageId)</Product>
<Copyright>Copyright (C) $([System.DateTime]::Now.Year) Nikolay Pianikov</Copyright>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<ImmutypeAPI>False</ImmutypeAPI>

<!--<AnalyzerRoslynVersion Condition="'$(AnalyzerRoslynVersion)'==''">4.3</AnalyzerRoslynVersion>
<AnalyzerRoslynPackageVersion Condition="'$(AnalyzerRoslynPackageVersion)'==''">4.3.1</AnalyzerRoslynPackageVersion>-->
Expand All @@ -28,6 +29,10 @@
<DefineConstants>$(DefineConstants);$(RolsynVersions)</DefineConstants>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="ImmutypeAPI" />
</ItemGroup>

<Target Name="Info" BeforeTargets="Build">
<Message Text="Roslyn $(AnalyzerRoslynPackageVersion)" Importance="high"/>
</Target>
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void SetupDI() =>
.Bind(3).To<Service3v3>()
.Bind(4).To<Service3v4>()
.Bind().To<Service4>()
.Root<CompositionRoot>(nameof(PureDIByCR), kind: RootKinds.Method | RootKinds.Partial);
.Root<CompositionRoot>(nameof(TestPureDIByCR), kind: RootKinds.Method | RootKinds.Partial);

protected override TActualContainer? CreateContainer<TActualContainer, TAbstractContainer>()
where TActualContainer : class =>
Expand All @@ -39,16 +39,16 @@ private static void SetupDI() =>
.TryCreate();

[Benchmark(Description = "Pure.DI Resolve<T>()")]
public CompositionRoot PureDI() => Resolve<CompositionRoot>();
public CompositionRoot TestPureDI() => Resolve<CompositionRoot>();

[Benchmark(Description = "Pure.DI Resolve(Type)")]
public object PureDINonGeneric() => Resolve(typeof(CompositionRoot));
public object TestPureDINonGeneric() => Resolve(typeof(CompositionRoot));

[Benchmark(Description = "Pure.DI composition root")]
public partial CompositionRoot PureDIByCR();
public partial CompositionRoot TestPureDIByCR();

[Benchmark(Description = "Hand Coded", Baseline = true)]
public CompositionRoot HandCoded() =>
public CompositionRoot TestHandCoded() =>
new(
new Service1(
new Service2Array(
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private static void SetupDI() =>
.Bind(3).To<Service3v3>()
.Bind(4).To<Service3v4>()
.Bind().To<Service4>()
.Root<CompositionRoot>(nameof(PureDIByCR), kind: RootKinds.Method | RootKinds.Partial);
.Root<CompositionRoot>(nameof(TestPureDIByCR), kind: RootKinds.Method | RootKinds.Partial);

protected override TActualContainer? CreateContainer<TActualContainer, TAbstractContainer>()
where TActualContainer : class =>
Expand All @@ -39,16 +39,16 @@ private static void SetupDI() =>
.TryCreate();

[Benchmark(Description = "Pure.DI Resolve<T>()")]
public CompositionRoot PureDI() => Resolve<CompositionRoot>();
public CompositionRoot TestPureDI() => Resolve<CompositionRoot>();

[Benchmark(Description = "Pure.DI Resolve(Type)")]
public object PureDINonGeneric() => Resolve(typeof(CompositionRoot));
public object TestPureDINonGeneric() => Resolve(typeof(CompositionRoot));

[Benchmark(Description = "Pure.DI composition root")]
public partial CompositionRoot PureDIByCR();
public partial CompositionRoot TestPureDIByCR();

[Benchmark(Description = "Hand Coded", Baseline = true)]
public CompositionRoot HandCoded() =>
public CompositionRoot TestHandCoded() =>
new(
new Service1(new Service2Enum(EnumerableOfIService3())),
new Service2Enum(EnumerableOfIService3()),
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Func.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static void SetupDI() =>
.Bind().To<Service2Func>()
.Bind().To<Service3>()
.Bind().To<Service4>()
.Root<CompositionRoot>(nameof(PureDIByCR), kind: RootKinds.Method | RootKinds.Partial);
.Root<CompositionRoot>(nameof(TestPureDIByCR), kind: RootKinds.Method | RootKinds.Partial);

protected override TActualContainer? CreateContainer<TActualContainer, TAbstractContainer>()
where TActualContainer : class =>
Expand All @@ -33,16 +33,16 @@ private static void SetupDI() =>
.TryCreate();

[Benchmark(Description = "Pure.DI Resolve<T>()")]
public CompositionRoot PureDI() => Resolve<CompositionRoot>();
public CompositionRoot TestPureDI() => Resolve<CompositionRoot>();

[Benchmark(Description = "Pure.DI Resolve(Type)")]
public object PureDINonGeneric() => Resolve(typeof(CompositionRoot));
public object TestPureDINonGeneric() => Resolve(typeof(CompositionRoot));

[Benchmark(Description = "Pure.DI composition root")]
public partial CompositionRoot PureDIByCR();
public partial CompositionRoot TestPureDIByCR();

[Benchmark(Description = "Hand Coded", Baseline = true)]
public CompositionRoot HandCoded()
public CompositionRoot TestHandCoded()
{
var func = new Func<IService3>(
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Singleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private static void SetupDI() =>
.Bind().To<Service2>()
.Bind().To<Service3>()
.Bind().As(Lifetime.Scoped).To<Service4>()
.Root<CompositionRoot>(nameof(PureDIByCR), kind: RootKinds.Method | RootKinds.Partial);
.Root<CompositionRoot>(nameof(TestPureDIByCR), kind: RootKinds.Method | RootKinds.Partial);

protected override TActualContainer? CreateContainer<TActualContainer, TAbstractContainer>()
where TActualContainer : class =>
Expand All @@ -35,16 +35,16 @@ private static void SetupDI() =>
.TryCreate();

[Benchmark(Description = "Pure.DI Resolve<T>()")]
public CompositionRoot PureDI() => Resolve<CompositionRoot>();
public CompositionRoot TestPureDI() => Resolve<CompositionRoot>();

[Benchmark(Description = "Pure.DI Resolve(Type)")]
public object PureDINonGeneric() => Resolve(typeof(CompositionRoot));
public object TestPureDINonGeneric() => Resolve(typeof(CompositionRoot));

[Benchmark(Description = "Pure.DI composition root")]
public partial CompositionRoot PureDIByCR();
public partial CompositionRoot TestPureDIByCR();

[Benchmark(Description = "Hand Coded", Baseline = true)]
public CompositionRoot HandCoded() =>
public CompositionRoot TestHandCoded() =>
new(
Singletons.Service1,
new Service2(
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/Pure.DI.Benchmarks/Benchmarks/Transient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private static void SetupDI() =>
.Bind().To<Service2>()
.Bind().To<Service3>()
.Bind().To<Service4>()
.Root<CompositionRoot>(nameof(PureDIByCR), kind: RootKinds.Method | RootKinds.Partial);
.Root<CompositionRoot>(nameof(TestPureDIByCR), kind: RootKinds.Method | RootKinds.Partial);

protected override TActualContainer? CreateContainer<TActualContainer, TAbstractContainer>()
where TActualContainer : class =>
Expand All @@ -32,16 +32,16 @@ private static void SetupDI() =>
.TryCreate();

[Benchmark(Description = "Pure.DI Resolve<T>()")]
public CompositionRoot PureDI() => Resolve<CompositionRoot>();
public CompositionRoot TestPureDI() => Resolve<CompositionRoot>();

[Benchmark(Description = "Pure.DI Resolve(Type)")]
public object PureDINonGeneric() => Resolve(typeof(CompositionRoot));
public object TestPureDINonGeneric() => Resolve(typeof(CompositionRoot));

[Benchmark(Description = "Pure.DI composition root")]
public partial CompositionRoot PureDIByCR();
public partial CompositionRoot TestPureDIByCR();

[Benchmark(Description = "Hand Coded", Baseline = true)]
public CompositionRoot HandCoded() =>
public CompositionRoot TestHandCoded() =>
new(
new Service1(
new Service2(
Expand Down
8 changes: 4 additions & 4 deletions build/Benchmarks/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ public BuildStatus Analyze(IEnumerable<Benchmark> benchmarks, params Thresholds[
return status;
}

private BuildStatus CheckThreshold(string name, double? warningThreshold, double? errorThreshold, double baseline, double value, string benchmarkType, string benchmarkMethod)
private static BuildStatus CheckThreshold(string name, double? warningThreshold, double? errorThreshold, double baseline, double value, string benchmarkType, string benchmarkMethod)
{
var ratio = value / baseline;
if (errorThreshold > double.Epsilon && ratio >= errorThreshold)
if (errorThreshold > double.Epsilon && ratio > errorThreshold)
{
Error(CreateMessage(name, errorThreshold, ratio, benchmarkType, benchmarkMethod, "must"));
return BuildStatus.Fail;
}

// ReSharper disable once InvertIf
if (warningThreshold > double.Epsilon && ratio >= warningThreshold)
if (warningThreshold > double.Epsilon && ratio > warningThreshold)
{
Error(CreateMessage(name, warningThreshold, ratio, benchmarkType, benchmarkMethod, "could"));
Warning(CreateMessage(name, warningThreshold, ratio, benchmarkType, benchmarkMethod, "could"));
return BuildStatus.Warnings;
}

Expand Down
3 changes: 3 additions & 0 deletions build/Benchmarks/BenchmarksDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Build.Benchmarks;

internal record BenchmarksDto(IReadOnlyCollection<Benchmark> Benchmarks);
99 changes: 0 additions & 99 deletions build/Benchmarks/Runner.cs

This file was deleted.

16 changes: 7 additions & 9 deletions build/BenchmarksTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ internal class BenchmarksTarget(
ITeamCityArtifactsWriter artifactsWriter)
: IInitializable, ITarget<int>
{
private static readonly string[] Reports =
private static readonly string[] Filters =
[
"Transient",
"Singleton",
"Func",
"Array",
"Enum"
"Pure.DI.Benchmarks.Benchmarks.*"
];

public Task InitializeAsync() => commands.Register(
Expand All @@ -40,14 +36,16 @@ public Task<int> RunAsync(CancellationToken cancellationToken)
new DotNetRun()
.WithProject(Path.Combine("benchmarks", "Pure.DI.Benchmarks", "Pure.DI.Benchmarks.csproj"))
.WithConfiguration(settings.Configuration)
.WithArgs("--artifacts", artifactsDirectory, "--", "--filter")
.AddArgs(Reports.Select(filter => $"*{filter}*").ToArray())
.WithArgs(
"--artifacts", artifactsDirectory,
"--", "--filter")
.AddArgs(Filters.Select(filter => filter).ToArray())
.Run()
.Succeed("Benchmarking");
}

var index = 0;
foreach (var reportName in Reports)
foreach (var reportName in Filters)
{
var reportFileName = Path.Combine(artifactsDirectory, "results", $"Pure.DI.Benchmarks.Benchmarks.{reportName}-report");
var reportFileNameHtml = reportFileName + ".html";
Expand Down
Loading

0 comments on commit d85ddf9

Please sign in to comment.