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);
}
}
}