NSubstitute 在基准测试中分配内存

问题描述

我正在使用 https://graph.microsoft.com/v1.0/users?$filter=mail ne null&&$expand=manager($levels=1;$select=id)&$count=true 来模拟我的数据库调用以进行基准测试。 对于我的基准测试,我使用 NSubstitute。尽管在我的替代方法中没有分配内存,但我正在获得内存分配。 我需要知道是什么导致了这种内存分配,并根据计算出的字节数。

BenchmarkDotNet

在我的 TeamManager 中:

    [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);
        }
    }

这是我的基准测试结果:

    public async Task<string> GetPlayerHistory(string realLeagueId)
    {
        return LocalCacheController.Instance.GetRealLeagueGroupId(realLeagueId);      
    }

你能告诉我为什么虽然我正在替换该方法但仍然分配了内存以及为什么它是如何计算的?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)