Skip to content

Commit

Permalink
feat: add first call benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyMakkison committed Jun 23, 2024
1 parent 8120a95 commit a17f0b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Refit.Benchmarks;

public interface IPerformanceApi
public interface IPerformanceService
{
[Get("/users")]
public Task<string> ConstantRoute();
Expand Down
4 changes: 2 additions & 2 deletions Refit.Benchmarks/PerformanceBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Refit.Benchmarks;
[MemoryDiagnoser]
public class PerformanceBenchmark
{
private IPerformanceApi? service;
private IPerformanceService? service;

private const string Host = "https://github.com";
private SystemTextJsonContentSerializer systemTextJsonContentSerializer;
Expand All @@ -16,7 +16,7 @@ public Task SetupAsync()
{
systemTextJsonContentSerializer = new SystemTextJsonContentSerializer();
service =
RestService.For<IPerformanceApi>(
RestService.For<IPerformanceService>(
Host,
new RefitSettings(systemTextJsonContentSerializer)
{
Expand Down
19 changes: 16 additions & 3 deletions Refit.Benchmarks/StartupBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Refit.Benchmarks;
[MemoryDiagnoser]
public class StartupBenchmark
{
private IPerformanceService initialisedService;
private const string Host = "https://github.com";
private readonly RefitSettings settings = new RefitSettings()
{
Expand All @@ -16,21 +17,33 @@ public class StartupBenchmark
)
};


[IterationSetup(Targets = [nameof(FirstCallConstantRouteAsync), nameof(FirstCallComplexRequestAsync)])]
public void Setup()
{
initialisedService = RestService.For<IPerformanceService>(Host, settings);
}

[Benchmark]
public IPerformanceApi CreateService() => RestService.For<IPerformanceApi>(Host, settings);
public IPerformanceService CreateService() => RestService.For<IPerformanceService>(Host, settings);

[Benchmark]
public async Task<string> FirstCallConstantRouteAsync() => await initialisedService.ConstantRoute();

[Benchmark]
public async Task<string> ConstantRouteAsync()
{
var service = RestService.For<IPerformanceApi>(Host, settings);
var service = RestService.For<IPerformanceService>(Host, settings);
return await service.ConstantRoute();
}

[Benchmark]
public async Task<string> FirstCallComplexRequestAsync() => await initialisedService.ObjectRequest(new PathBoundObject(){SomeProperty = "myProperty", SomeQuery = "myQuery"});

[Benchmark]
public async Task<string> ComplexRequestAsync()
{
var service = RestService.For<IPerformanceApi>(Host, settings);
var service = RestService.For<IPerformanceService>(Host, settings);
return await service.ObjectRequest(new PathBoundObject(){SomeProperty = "myProperty", SomeQuery = "myQuery"});
}
}

0 comments on commit a17f0b4

Please sign in to comment.