Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/Benchmark/CollectionBenchmark.cs
Misaki c0a0861897
Some checks failed
Publish NuGet Packages / publish (pull_request) Failing after 1m5s
Improve memory safety and alignment handling
- Updated `.gitignore` to include `.vscode/` and clarified comments.
- Introduced `SafeHandle` for managing memory alignment and safe access.
- Refactored `UnsafeArray<T>` to add bounds checking and alignment logic.
- Added `IUnsafeHashCollection<T>` for specialized hash-based collections.
- Refactored `UnsafeHashMap<TKey, TValue>` and `UnsafeHashSet<T>` to use `HashMapHelper<TKey>` with alignment support.
- Made `UnsafeSlotMap<T>` methods `readonly` for immutability.
- Enhanced `HashMapHelper<TKey>` with alignment-aware buffer management and validation.
- Updated benchmarks to use `UnsafeArray<Vector256<int>>` and added capacity checks.
- Incremented assembly version to `1.1.3` in `Misaki.HighPerformance.LowLevel.csproj`.
- Updated `Program.cs` to run `CollectionBenchmark` and demonstrate safe disposal handling.
2025-11-18 01:25:40 +09:00

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, Allocator.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;
}
}
}