diff --git a/TUnit.SourceGenerator.Benchmarks/Program.cs b/TUnit.SourceGenerator.Benchmarks/Program.cs index 430f60738e..2a73e62c73 100644 --- a/TUnit.SourceGenerator.Benchmarks/Program.cs +++ b/TUnit.SourceGenerator.Benchmarks/Program.cs @@ -12,4 +12,5 @@ { BenchmarkRunner.Run(); // BenchmarkRunner.Run(); + // BenchmarkRunner.Run(); } diff --git a/TUnit.SourceGenerator.Benchmarks/StaticPropertyInitializationGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/StaticPropertyInitializationGeneratorBenchmarks.cs new file mode 100644 index 0000000000..e702dbee70 --- /dev/null +++ b/TUnit.SourceGenerator.Benchmarks/StaticPropertyInitializationGeneratorBenchmarks.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 StaticPropertyInitializationGeneratorBenchmarks +{ + private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj"; + + private MSBuildWorkspace? _workspace; + private GeneratorDriver? _sampleDriver; + private Compilation? _sampleCompilation; + + [GlobalSetup(Target = nameof(RunGenerator))] + public void SetupRunGenerator() => + (_sampleCompilation, _sampleDriver, _workspace) = + WorkspaceHelper.SetupAsync(SampleProjectPath) + .GetAwaiter() + .GetResult(); + + [Benchmark] + public GeneratorDriver RunGenerator() => _sampleDriver!.RunGeneratorsAndUpdateCompilation(_sampleCompilation!, out _, out _); + + [GlobalCleanup] + public void Cleanup() + { + _workspace?.Dispose(); + } +}