Add benchmark method and improve Unsafe collections

Added a new benchmark method `For` in `ParallelNoiseBenchmark` to test gradient noise generation.
Added demonstration code for `UnsafeArray` in `Program.cs` with a custom `Test` struct.

Changed property accessors in `IUnsafeCollection<T>` to use `ref` returns for better memory efficiency.
Changed property accessors and indexers in `UnsafeArray<T>`, `UnsafeList<T>`, and `UnsafeQueue<T>` to return `ref` types.
Changed `TryDequeue` in `UnsafeQueue<T>` to return a default value instead of null.
Changed `Clear` and `Dispose` methods in `UnsafeQueue<T>` to reset size and offset.

Removed commented-out `BenchmarkRunner` code in `Program.cs`.
This commit is contained in:
2025-03-27 12:51:00 +09:00
parent cb69add265
commit 060b4c9477
6 changed files with 140 additions and 33 deletions

View File

@@ -92,4 +92,17 @@ public class ParallelNoiseBenchmark
buffers[i] = NoiseJob.GradientNoise(uv);
});
}
[Benchmark]
public void For()
{
using var buffers = new UnsafeArray<float>(_LENGTH, AllocationType.UnInitialized);
for (var i = 0; i < _LENGTH; i++)
{
var x = i % _WIDTH;
var y = i / _HEIGHT;
var uv = new Vector2(x, y);
buffers[i] = NoiseJob.GradientNoise(uv);
}
}
}

View File

@@ -1,4 +1,37 @@
using BenchmarkDotNet.Running;
using Misaki.HighPerformance.Test;
//using BenchmarkDotNet.Running;
//using Misaki.HighPerformance.Test;
BenchmarkRunner.Run<ParallelNoiseBenchmark>();
//BenchmarkRunner.Run<ParallelNoiseBenchmark>();
using Misaki.HighPerformance.Unsafe.Collections;
using var test = new UnsafeArray<Test>(10, AllocationType.UnInitialized);
for (var i = 0; i < 10; i++)
{
var t = new Test();
t.buffers[0] = i;
test[i] = t;
}
test.ReAlloc(20);
for (var i = 0; i < 10; i++)
{
Console.WriteLine(test[i].buffers[0]);
}
struct Test : IDisposable
{
public UnsafeArray<float> buffers;
public Test()
{
buffers = new UnsafeArray<float>(1, AllocationType.UnInitialized);
}
public void Dispose()
{
buffers.Dispose();
}
}