diff --git a/TUnit.SourceGenerator.Benchmarks/AotConverterGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/AotConverterGeneratorBenchmarks.cs index 7b53b6d133..bd4f58b93f 100644 --- a/TUnit.SourceGenerator.Benchmarks/AotConverterGeneratorBenchmarks.cs +++ b/TUnit.SourceGenerator.Benchmarks/AotConverterGeneratorBenchmarks.cs @@ -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(SampleProjectPath) .GetAwaiter() .GetResult(); [Benchmark] - public GeneratorDriver RunGenerator() => _sampleDriver!.RunGeneratorsAndUpdateCompilation(_sampleCompilation!, out _, out _); + public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); [GlobalCleanup] public void Cleanup() diff --git a/TUnit.SourceGenerator.Benchmarks/DynamicTestsGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/DynamicTestsGeneratorBenchmarks.cs new file mode 100644 index 0000000000..35caefc059 --- /dev/null +++ b/TUnit.SourceGenerator.Benchmarks/DynamicTestsGeneratorBenchmarks.cs @@ -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(SampleProjectPath) + .GetAwaiter() + .GetResult(); + + [Benchmark] + public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); + + [GlobalCleanup] + public void Cleanup() + { + _workspace?.Dispose(); + } +} diff --git a/TUnit.SourceGenerator.Benchmarks/HookMetadataGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/HookMetadataGeneratorBenchmarks.cs new file mode 100644 index 0000000000..926e79f9b6 --- /dev/null +++ b/TUnit.SourceGenerator.Benchmarks/HookMetadataGeneratorBenchmarks.cs @@ -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(SampleProjectPath) + .GetAwaiter() + .GetResult(); + + [Benchmark] + public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); + + [GlobalCleanup] + public void Cleanup() + { + _workspace?.Dispose(); + } +} diff --git a/TUnit.SourceGenerator.Benchmarks/InfrastructureGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/InfrastructureGeneratorBenchmarks.cs new file mode 100644 index 0000000000..54ce2aa3f1 --- /dev/null +++ b/TUnit.SourceGenerator.Benchmarks/InfrastructureGeneratorBenchmarks.cs @@ -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(SampleProjectPath) + .GetAwaiter() + .GetResult(); + + [Benchmark] + public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); + + [GlobalCleanup] + public void Cleanup() + { + _workspace?.Dispose(); + } +} diff --git a/TUnit.SourceGenerator.Benchmarks/Program.cs b/TUnit.SourceGenerator.Benchmarks/Program.cs index 2a73e62c73..58addd6760 100644 --- a/TUnit.SourceGenerator.Benchmarks/Program.cs +++ b/TUnit.SourceGenerator.Benchmarks/Program.cs @@ -11,6 +11,10 @@ else { BenchmarkRunner.Run(); - // BenchmarkRunner.Run(); + // BenchmarkRunner.Run(); + // BenchmarkRunner.Run(); // BenchmarkRunner.Run(); + // BenchmarkRunner.Run(); + // BenchmarkRunner.Run(); + // BenchmarkRunner.Run(); } diff --git a/TUnit.SourceGenerator.Benchmarks/PropertyInjectionSourceGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/PropertyInjectionSourceGeneratorBenchmarks.cs new file mode 100644 index 0000000000..41e92d4d80 --- /dev/null +++ b/TUnit.SourceGenerator.Benchmarks/PropertyInjectionSourceGeneratorBenchmarks.cs @@ -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(SampleProjectPath) + .GetAwaiter() + .GetResult(); + + [Benchmark] + public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); + + [GlobalCleanup] + public void Cleanup() + { + _workspace?.Dispose(); + } +} diff --git a/TUnit.SourceGenerator.Benchmarks/StaticPropertyInitializationGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/StaticPropertyInitializationGeneratorBenchmarks.cs index e702dbee70..ab91db7643 100644 --- a/TUnit.SourceGenerator.Benchmarks/StaticPropertyInitializationGeneratorBenchmarks.cs +++ b/TUnit.SourceGenerator.Benchmarks/StaticPropertyInitializationGeneratorBenchmarks.cs @@ -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(SampleProjectPath) .GetAwaiter() .GetResult(); [Benchmark] - public GeneratorDriver RunGenerator() => _sampleDriver!.RunGeneratorsAndUpdateCompilation(_sampleCompilation!, out _, out _); + public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); [GlobalCleanup] public void Cleanup() diff --git a/TUnit.SourceGenerator.Benchmarks/TestMetadataGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/TestMetadataGeneratorBenchmarks.cs index 17430eaa0e..56079b8cfd 100644 --- a/TUnit.SourceGenerator.Benchmarks/TestMetadataGeneratorBenchmarks.cs +++ b/TUnit.SourceGenerator.Benchmarks/TestMetadataGeneratorBenchmarks.cs @@ -2,7 +2,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.MSBuild; using TUnit.Core.SourceGenerator.Generators; -using TUnit.SourceGenerator.Benchmarks; namespace TUnit.SourceGenerator.Benchmarks; @@ -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(SampleProjectPath) .GetAwaiter() .GetResult(); [Benchmark] - public GeneratorDriver RunGenerator() => _sampleDriver!.RunGeneratorsAndUpdateCompilation(_sampleCompilation!, out _, out _); + public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); [GlobalCleanup] public void Cleanup()