-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Processing dotnet/runtime#116193 (comment) command:
Command
-intel
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using Microsoft.Extensions.Caching.Memory;
public class Program
{
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
Labels
No labels