优化对象池设计并新增性能与单元测试
石头 authored at 2025-09-20 08:32:20
500.00 B
X
using BenchmarkDotNet.Attributes;
using NewLife.Collections;

namespace XUnitTest.Collections;

/// <summary>Pool 性能基准</summary>
[MemoryDiagnoser]
public class PoolBenchmark
{
    private Pool<Object> _pool;

    [GlobalSetup]
    public void Setup()
    {
        _pool = new Pool<Object>(128);
    }

    [Benchmark]
    public void GetReturn()
    {
        for (var i = 0; i < 100_000; i++)
        {
            var obj = _pool.Get();
            _pool.Return(obj);
        }
    }
}