I'm using NSubstitute
to mock my DB calls for my benchmarking.
For my benchmarking i'm using BenchmarkDotNet
. Im getting memory allocation although there is no memory allocated in my substituted method.
I need to know what causes this memory allocation and according to what the number of bytes is calculated.
[SimpleJob(RunStrategy.Monitoring, targetCount: 100)]
[MemoryDiagnoser]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class PlayerHistory
{
private static ILocalCache _localCache = Substitute.For<ILocalCache>();
[GlobalSetup]
public async Task Setup()
{
LocalCache.Instance.SetInstance(_localCache);
Mock();
}
private void Mock()
{
LocalCacheController.Instance.GetRealLeagueGroupId("").ReturnsForAnyArgs(BenchmarkConstants.RealLeagueId);
}
[Benchmark]
public async Task GetUsersInfoByUsers()
{
await TeamManager.Instance.GetPlayerHistory(BenchmarkConstants.RealLeagueId);
}
}
In my TeamManager:
public async Task<string> GetPlayerHistory(string realLeagueId)
{
return LocalCacheController.Instance.GetRealLeagueGroupId(realLeagueId);
}
This is my benchmark results:
| Method | Mean | Error | StdDev | Median | Gen 0 | Gen 1 | Gen 2 | Allocated |
|-------------------- |---------:|---------:|---------:|---------:|------:|------:|------:|----------:|
| GetUsersInfoByUsers | 63.66 us | 20.96 us | 61.79 us | 29.82 us | - | - | - | 376 B |
can you tell me why although i'm substituting the method there is still memory allocated and why how it's calculated?