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
@@ -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 AotConverterGeneratorBenchmarks
{
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<AotConverterGenerator>(SampleProjectPath)
.GetAwaiter()
.GetResult();

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

[GlobalCleanup]
public void Cleanup()
{
_workspace?.Dispose();
}
}
1 change: 1 addition & 0 deletions TUnit.SourceGenerator.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
else
{
BenchmarkRunner.Run<TestMetadataGeneratorBenchmarks>();
// BenchmarkRunner.Run<AotConverterGeneratorBenchmarks>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public class TestMetadataGeneratorBenchmarks
private GeneratorDriver? _sampleDriver;
private Compilation? _sampleCompilation;

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

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

[GlobalCleanup]
public void Cleanup()
Expand Down
Loading