所以,我在我的Main()
方法中有以下代码:
for (int x = 0; x < 100; x++) // to mimic BenchmarkDotnet runs
for (int y = 0; y < 10000; y++)
LogicUnderTest();
接下来,在测试中我有以下的类
[MemoryDiagnoser, ShortRunJob]
public class TestBenchmark
{
[Benchmark]
public void Test_1()
{
for (int i = 0; i < 10000; i++)
LogicUnderTest();
}
}
在
dotMemory
下运行了约 6 分钟的 Main()
后,我收到了以下结果。
该应用程序从10Mb
开始,增加到14Mb
。但是,当我运行
BenchmarkDotnet
测试时,出现以下情况![enter image description here](https://istack.dev59.com/kWgou.webp)
我发现已经分配了
2.6GB
。这是怎么回事?似乎一点都不好。此外,我看不到Gen1
和Gen2
列。这是否意味着代码没有在它们中分配任何东西,因此没有什么可以显示?如何解释这些结果?在
DotMemory
中,它似乎完全正常,但在BenchmarkDotNet
中却不正常。我对BenchmarkDotnet
还比较新,对于有关结果的任何信息将非常有帮助。附:
LogicUnderTest()
大量使用字符串。附注:大概来说,
LogicUnderTest
的实现如下:void LogicUnderTest()
{
var dict = new Dictionary<int, string>();
for (int j = 0; j < 1250; j++)
dict.Add(j, $"index_{j}");
string.Join(",", dict.Values);
}