4

I have a method which posts to external web api

    [Benchmark]
    public async Task SendData()
    {
        var Messages = new List<Messages>() {Data.SampleMessage)};
        
        var service= _host.Services.GetService<ISendMessages>()!;
        var response = await service.SendMesages(Messages);

    }

and have this count setup as follows: IterationCount=1, WarmupCount = 0, LaunchCount = 0 ,InvocationCount=1, UnrollFactor=1

what i want is run this method just once but i can't since that external api is called twice and when i send 5 messages 10 messages are posted. Please tell me why this is happening.Thanks

NoFX
  • 41
  • 5
  • 1
    As an aside, there is little point to using BDN if all you want is to time a particular piece of code *once*. The whole reason all this warmup and iteration stuff is happening is so benchmarks are representative, and not affected by outliers through system delays. If you're going to bypass all of that and all you're doing is timing responsiveness of an external service, you may as well just use a `Stopwatch` to time the call. – Jeroen Mostert Sep 21 '22 at 08:12
  • You should not use BenchmarkDotNet in your production code. This library is used in testing for performance measurements. – Alexander Petrov Sep 21 '22 at 12:24
  • @AlexanderPetrov actually it's a test method i just want that method run only once – NoFX Sep 21 '22 at 17:26

0 Answers0