Skip to content

Commit

Permalink
feat: added larger benchmark (#1848)
Browse files Browse the repository at this point in the history
Co-authored-by: Chris Pulman <chris.pulman@yahoo.com>
  • Loading branch information
TimothyMakkison and ChrisPulman authored Sep 29, 2024
1 parent 101afad commit 27b436c
Show file tree
Hide file tree
Showing 2 changed files with 1,780 additions and 36 deletions.
61 changes: 25 additions & 36 deletions Refit.Benchmarks/SourceGeneratorBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,6 @@ namespace Refit.Benchmarks;
[MemoryDiagnoser]
public class SourceGeneratorBenchmark
{
#region SourceText
private const string SmallInterface =
"""
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Refit;

namespace RefitGeneratorTest;

public interface IReallyExcitingCrudApi<T, in TKey> where T : class
{
[Post("")]
Task<T> Create([Body] T payload);

[Get("")]
Task<List<T>> ReadAll();

[Get("/{key}")]
Task<T> ReadOne(TKey key);

[Put("/{key}")]
Task Update(TKey key, [Body]T payload);

[Delete("/{key}")]
Task Delete(TKey key);
}
""";
#endregion

static readonly MetadataReference RefitAssembly = MetadataReference.CreateFromFile(
typeof(GetAttribute).Assembly.Location,
documentation: XmlDocumentationProvider.CreateFromFile(
Expand Down Expand Up @@ -97,7 +63,7 @@ private void Setup(string sourceText)
}

[GlobalSetup(Target = nameof(Compile))]
public void SetupSmall() => Setup(SmallInterface);
public void SetupSmall() => Setup(SourceGeneratorBenchmarksProjects.SmallInterface);

[Benchmark]
public GeneratorDriver Compile()
Expand All @@ -108,7 +74,7 @@ public GeneratorDriver Compile()
[GlobalSetup(Target = nameof(Cached))]
public void SetupCached()
{
Setup(SmallInterface);
Setup(SourceGeneratorBenchmarksProjects.SmallInterface);
driver = (CSharpGeneratorDriver)driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _);
compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText("struct MyValue {}"));
}
Expand All @@ -118,4 +84,27 @@ public GeneratorDriver Cached()
{
return driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _);
}

[GlobalSetup(Target = nameof(CompileMany))]
public void SetupMany() => Setup(SourceGeneratorBenchmarksProjects.ManyInterfaces);

[Benchmark]
public GeneratorDriver CompileMany()
{
return driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _);
}

[GlobalSetup(Target = nameof(CachedMany))]
public void SetupCachedMany()
{
Setup(SourceGeneratorBenchmarksProjects.ManyInterfaces);
driver = (CSharpGeneratorDriver)driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _);
compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText("struct MyValue {}"));
}

[Benchmark]
public GeneratorDriver CachedMany()
{
return driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out _);
}
}
Loading

0 comments on commit 27b436c

Please sign in to comment.