Replaced the deprecated Allocator API with the new AllocationHandle API across the codebase. Updated constructors, methods, and tests to use AllocationHandle for memory management. Marked Allocator-based methods as [Obsolete] and provided alternatives. Added OwnershipTransferAnalyzer to detect ownership transfer issues and introduced OwnershipTransferAttribute for marking parameters. Enhanced DefensiveCopyAnalyzer with additional checks for readonly and ValueType instances. Refactored internal memory management in AllocationManager and updated benchmarks, utilities, and documentation to reflect the changes. BREAKING CHANGE: Deprecated Allocator API in favor of AllocationHandle. Updated constructors and methods to use AllocationHandle. Users must migrate to the new API.
49 lines
1.0 KiB
C#
49 lines
1.0 KiB
C#
using BenchmarkDotNet.Attributes;
|
|
using Misaki.HighPerformance.LowLevel.Buffer;
|
|
using Misaki.HighPerformance.LowLevel.Collections;
|
|
using System.Runtime.Intrinsics;
|
|
|
|
namespace Misaki.HighPerformance.Test.Benchmark;
|
|
|
|
public class CollectionBenchmark
|
|
{
|
|
private UnsafeArray<Vector256<int>> _array;
|
|
|
|
[Params(10, 100, 1000)]
|
|
public int count;
|
|
|
|
[GlobalSetup]
|
|
public void Setup()
|
|
{
|
|
_array = new UnsafeArray<Vector256<int>>(count, AllocationHandle.Persistent);
|
|
}
|
|
|
|
[GlobalCleanup]
|
|
public void Cleanup()
|
|
{
|
|
_array.Dispose();
|
|
}
|
|
|
|
[Benchmark]
|
|
public void WithCapacityChecks()
|
|
{
|
|
for (var i = 0; i < _array.Count; i++)
|
|
{
|
|
if (i < 0 || i >= _array.Count)
|
|
{
|
|
throw new IndexOutOfRangeException();
|
|
}
|
|
|
|
_array[i] = default;
|
|
}
|
|
}
|
|
|
|
[Benchmark]
|
|
public void WithoutCapacityChecks()
|
|
{
|
|
for (var i = 0; i < _array.Count; i++)
|
|
{
|
|
_array[i] = default;
|
|
}
|
|
}
|
|
} |