Skip to content

Benchmarks for #116193 (jkotas) #571

@EgorBot

Description

@EgorBot

Processing dotnet/runtime#116193 (comment) command:

Command

-intel

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Microsoft.Extensions.Caching.Memory;

public class MemoryCacheTest
{
    MemoryCache _memCache;

    [GlobalSetup(Targets = new[] { nameof(GetHitParallel) })]
    public void SetupBasic()
    {
        _memCache = new MemoryCache(new MemoryCacheOptions() { TrackStatistics = true });
        for (var i = 0; i < 1024; i++)
        {
            _memCache.Set(i.ToString(), new object());
        }
    }

    [GlobalCleanup(Targets = new[] { nameof(GetHitParallel) })]
    public void CleanupBasic() => _memCache.Dispose();


    [Benchmark]
    public async Task GetHitParallel()
    {
        await Task.WhenAll(
            Enumerable
            .Range(0, Environment.ProcessorCount)
            .Select(_ =>
            Task.Run(async delegate
            {
                for (int i = 0; i < 1000000; i++)
                {
                    var x = _memCache.Get("256");
                    if (x == null) Environment.FailFast("Unexpected!");
                }
            })));

    }
}

(EgorBot will reply in this issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions