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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user