Skip to content

[MemoryDiagnoser] Shows strange values for 'almost' empty benchmarks #2321

Closed as not planned
@ApmeM

Description

@ApmeM

I have created a very simple almost empty benchmark.
Full code is here:

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

[MemoryDiagnoser]
public class Program
{
    public static void Main(string[] args)
    {
        BenchmarkRunner.Run<Program>();
    }

    [Benchmark]
    public void Test()
    {
        for (var i = 0; i < 10000000; i++)
        {
        }
    }
}

So effectively there is only a single loop from 1 to 10000000 without any calculations in it.

The benchmark result shows this:

BenchmarkDotNet=v0.13.1, OS=debian 11
Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores
.NET SDK=7.0.203
[Host] : .NET 6.0.10 (6.0.1022.47605), X64 RyuJIT
DefaultJob : .NET 6.0.10 (6.0.1022.47605), X64 RyuJIT

Method Mean Error StdDev Allocated
Test 2.605 ms 0.0169 ms 0.0141 ms 3 B

Where those 3 bytes come from?
I run this code with this command:

dotnet run -c Release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions