Files
Andrey Ilnitsky 1cdaadbfaa - target net472 and netstandard2.0
- microsoft.extensions.logging 5.0.0
- microsoft.extensions.configuration 5.0.0
2021-07-16 18:04:31 -07:00

41 lines
1.1 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace DotNetty.Microbench.Concurrency
{
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using DotNetty.Common;
[SimpleJob(RuntimeMoniker.NetCoreApp31)]
[BenchmarkCategory("Concurrency")]
public class FastThreadLocalBenchmark
{
ThreadLocalArray threadLocalArray;
[GlobalSetup]
public void GlobalSetup()
{
this.threadLocalArray = new ThreadLocalArray(new byte[128]);
}
[Benchmark]
public byte[] Get() => this.threadLocalArray.Value;
[GlobalCleanup]
public void GlobalCleanup() => FastThreadLocal.Destroy();
sealed class ThreadLocalArray : FastThreadLocal<byte[]>
{
readonly byte[] array;
public ThreadLocalArray(byte[] array)
{
this.array = array;
}
protected override byte[] GetInitialValue() => this.array;
}
}
}