So, I have a following piece of code in my Main()
method
for (int x = 0; x < 100; x++) // to mimic BenchmarkDotnet runs
for (int y = 0; y < 10000; y++)
LogicUnderTest();
Next, I have the following class under the test
[MemoryDiagnoser, ShortRunJob]
public class TestBenchmark
{
[Benchmark]
public void Test_1()
{
for (int i = 0; i < 10000; i++)
LogicUnderTest();
}
}
After running Main()
under dotMemory
for around 6 minutes, I receive the following results
The app starts at 10Mb
and goes up to 14Mb
.
But when I run BenchmarkDotnet
test I get this
I see that I've got 2.6GB
allocated. What? It seems not good at all. Also, I can't see Gen1
and Gen2
columns. Does it mean that the code didn't allocate anything in them so there is nothing to display?
How can I interpret the results? It seems totally fine in DotMemory
, but not ok in BenchmarkDotNet
. I'm pretty new at BenchmarkDotnet
and will be helpful for any information regarding the results.
PS. LogicUnderTest()
works extensively with strings.
PSS. Roughly, LogicUnderTest
is implemented like this
void LogicUnderTest()
{
var dict = new Dictionary<int, string>();
for (int j = 0; j < 1250; j++)
dict.Add(j, $"index_{j}");
string.Join(",", dict.Values);
}