Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public class AotConverterGeneratorBenchmarks
private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj";

private MSBuildWorkspace? _workspace;
private GeneratorDriver? _sampleDriver;
private Compilation? _sampleCompilation;
private GeneratorDriver? _driver;
private Compilation? _compilation;

[GlobalSetup(Target = nameof(RunGenerator))]
public void SetupRunGenerator() =>
(_sampleCompilation, _sampleDriver, _workspace) =
(_compilation, _driver, _workspace) =
WorkspaceHelper.SetupAsync<AotConverterGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

[Benchmark]
public GeneratorDriver RunGenerator() => _sampleDriver!.RunGeneratorsAndUpdateCompilation(_sampleCompilation!, out _, out _);
public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _);

[GlobalCleanup]
public void Cleanup()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using BenchmarkDotNet.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
using TUnit.Core.SourceGenerator.CodeGenerators;

namespace TUnit.SourceGenerator.Benchmarks;

[MemoryDiagnoser]
[InProcess]
public class DynamicTestsGeneratorBenchmarks
{
private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj";

private MSBuildWorkspace? _workspace;
private GeneratorDriver? _driver;
private Compilation? _compilation;

[GlobalSetup(Target = nameof(RunGenerator))]
public void SetupRunGenerator() =>
(_compilation, _driver, _workspace) =
WorkspaceHelper.SetupAsync<DynamicTestsGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

[Benchmark]
public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _);

[GlobalCleanup]
public void Cleanup()
{
_workspace?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using BenchmarkDotNet.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
using TUnit.Core.SourceGenerator.Generators;

namespace TUnit.SourceGenerator.Benchmarks;

[MemoryDiagnoser]
[InProcess]
public class HookMetadataGeneratorBenchmarks
{
private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj";

private MSBuildWorkspace? _workspace;
private GeneratorDriver? _driver;
private Compilation? _compilation;

[GlobalSetup(Target = nameof(RunGenerator))]
public void SetupRunGenerator() =>
(_compilation, _driver, _workspace) =
WorkspaceHelper.SetupAsync<HookMetadataGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

[Benchmark]
public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _);

[GlobalCleanup]
public void Cleanup()
{
_workspace?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using BenchmarkDotNet.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
using TUnit.Core.SourceGenerator.CodeGenerators;

namespace TUnit.SourceGenerator.Benchmarks;

[MemoryDiagnoser]
[InProcess]
public class InfrastructureGeneratorBenchmarks
{
private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj";

private MSBuildWorkspace? _workspace;
private GeneratorDriver? _driver;
private Compilation? _compilation;

[GlobalSetup(Target = nameof(RunGenerator))]
public void SetupRunGenerator() =>
(_compilation, _driver, _workspace) =
WorkspaceHelper.SetupAsync<InfrastructureGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

[Benchmark]
public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _);

[GlobalCleanup]
public void Cleanup()
{
_workspace?.Dispose();
}
}
6 changes: 5 additions & 1 deletion TUnit.SourceGenerator.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
else
{
BenchmarkRunner.Run<TestMetadataGeneratorBenchmarks>();
// BenchmarkRunner.Run<AotConverterGeneratorBenchmarks>();
// BenchmarkRunner.Run<DynamicTestsGeneratorBenchmarks>();
// BenchmarkRunner.Run<InfrastructureGeneratorBenchmarks>();
// BenchmarkRunner.Run<StaticPropertyInitializationGeneratorBenchmarks>();
// BenchmarkRunner.Run<AotConverterGeneratorBenchmarks>();
// BenchmarkRunner.Run<HookMetadataGeneratorBenchmarks>();
// BenchmarkRunner.Run<PropertyInjectionSourceGeneratorBenchmarks>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using BenchmarkDotNet.Attributes;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
using TUnit.Core.SourceGenerator.Generators;

namespace TUnit.SourceGenerator.Benchmarks;

[MemoryDiagnoser]
[InProcess]
public class PropertyInjectionSourceGeneratorBenchmarks
{
private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj";

private MSBuildWorkspace? _workspace;
private GeneratorDriver? _driver;
private Compilation? _compilation;

[GlobalSetup(Target = nameof(RunGenerator))]
public void SetupRunGenerator() =>
(_compilation, _driver, _workspace) =
WorkspaceHelper.SetupAsync<PropertyInjectionSourceGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

[Benchmark]
public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _);

[GlobalCleanup]
public void Cleanup()
{
_workspace?.Dispose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public class StaticPropertyInitializationGeneratorBenchmarks
private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj";

private MSBuildWorkspace? _workspace;
private GeneratorDriver? _sampleDriver;
private Compilation? _sampleCompilation;
private GeneratorDriver? _driver;
private Compilation? _compilation;

[GlobalSetup(Target = nameof(RunGenerator))]
public void SetupRunGenerator() =>
(_sampleCompilation, _sampleDriver, _workspace) =
(_compilation, _driver, _workspace) =
WorkspaceHelper.SetupAsync<StaticPropertyInitializationGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

[Benchmark]
public GeneratorDriver RunGenerator() => _sampleDriver!.RunGeneratorsAndUpdateCompilation(_sampleCompilation!, out _, out _);
public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _);

[GlobalCleanup]
public void Cleanup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.MSBuild;
using TUnit.Core.SourceGenerator.Generators;
using TUnit.SourceGenerator.Benchmarks;

namespace TUnit.SourceGenerator.Benchmarks;

Expand All @@ -13,18 +12,18 @@ public class TestMetadataGeneratorBenchmarks
private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj";

private MSBuildWorkspace? _workspace;
private GeneratorDriver? _sampleDriver;
private Compilation? _sampleCompilation;
private GeneratorDriver? _driver;
private Compilation? _compilation;

[GlobalSetup(Target = nameof(RunGenerator))]
public void SetupRunGenerator() =>
(_sampleCompilation, _sampleDriver, _workspace) =
(_compilation, _driver, _workspace) =
WorkspaceHelper.SetupAsync<TestMetadataGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

[Benchmark]
public GeneratorDriver RunGenerator() => _sampleDriver!.RunGeneratorsAndUpdateCompilation(_sampleCompilation!, out _, out _);
public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _);

[GlobalCleanup]
public void Cleanup()
Expand Down
Loading