1

I do have an existing rest api project developed using asp.net core 3.1. At present we are planning to do code refactoring and optimize it. I came across BenchMarkDotNet (https://benchmarkdotnet.org/) recently. All the examples that I have come across are mostly targeted for console based applications. I wanted to leverage this in case of rest apis project too, but did not came across any reference examples in context to its usage.

Code:

[Route("api/[Action]")] [ApiController] [AllowModule(AppType = ApplicationType.Testing)] public class TestController : BaseController { private readonly ITestService _testService; public TestController(ITestService testService, ILogger logger) : base(logger) { _testService = testService ?? throw new ArgumentNullException(nameof(testService)); }

[HttpGet("{inspectionID:long}", Name = "GetDetails")]
[ResponseCache(CacheProfileName = "Never")]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public async Task<IEnumerable<TestDTO>> Get(long inspectionID) => await _testService.GetDetails(inspectionID);

}

Can anyone help me here by providing their guidance?

santosh kumar patro
  • 7,231
  • 22
  • 71
  • 143
  • Can you post a sample endpoint from one of your controllers? There are multiple ways to benchmark, and the "best" way may vary based on your implementation. – Luke Sep 27 '22 at 13:43
  • Thanks @Luke for your response. I have added the endpoint. Any help on this request is much appreciated – santosh kumar patro Sep 27 '22 at 14:29
  • So you have a choice here: do you want to 1) benchmark end-to-end REST response times (understanding that it's not representative of what actual clients will experience, due to networking delay variances) OR 2) benchmark your `TestService.GetDetails` method (and other methods)? – Luke Sep 27 '22 at 15:45
  • Option 2: TestService.GetDetails looks to be good in this case – santosh kumar patro Sep 27 '22 at 18:28
  • @Luke In this case TestService class is DI enabled. Can you please guide me how to benchmark DI enabled class. Any help on this request is much appreciated – santosh kumar patro Oct 04 '22 at 18:35

0 Answers0