mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-19 14:52:04 +08:00
1cdaadbfaa
- microsoft.extensions.logging 5.0.0 - microsoft.extensions.configuration 5.0.0
41 lines
1.1 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|