Files
Misaki.HighPerformance/Misaki.HighPerformance.Test/Benchmark/ParallelNoiseBenchmark.cs
Misaki 9c4faa107a feat(memory): transition to AllocationHandle API
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.
2026-04-12 17:50:12 +09:00

71 lines
1.8 KiB
C#

using BenchmarkDotNet.Attributes;
using Misaki.HighPerformance.Jobs;
using Misaki.HighPerformance.LowLevel.Buffer;
using Misaki.HighPerformance.LowLevel.Collections;
using Misaki.HighPerformance.Test.Jobs;
using System.Numerics;
namespace Misaki.HighPerformance.Test.Benchmark;
[MemoryDiagnoser]
public class ParallelNoiseBenchmark
{
private const int _WIDTH = 2048;
private const int _HEIGHT = 2048;
private const int _LENGTH = _WIDTH * _HEIGHT;
internal JobScheduler _jobScheduler = null!;
private UnsafeArray<float> _buffers;
[GlobalSetup]
public void Setup()
{
_jobScheduler = new JobScheduler(Environment.ProcessorCount);
_buffers = new UnsafeArray<float>(_LENGTH, AllocationHandle.Persistent);
}
[GlobalCleanup]
public void Cleanup()
{
_jobScheduler.Dispose();
_buffers.Dispose();
}
[Benchmark]
public unsafe void JobSystem()
{
var job = new NoiseJobVector()
{
buffers = (float*)_buffers.GetUnsafePtr(),
width = _WIDTH,
height = _HEIGHT
};
var handle = _jobScheduler.ScheduleParallel(ref job, _LENGTH, 64, -1, JobHandle.Invalid);
_jobScheduler.Wait(handle);
}
[Benchmark]
public void ParallelFor()
{
Parallel.For(0, _LENGTH, i =>
{
var x = i % _WIDTH;
var y = i / _HEIGHT;
var uv = new Vector2(x, y) / new Vector2(_WIDTH, _HEIGHT);
_buffers[i] = NoiseJobVector.GradientNoise(uv);
});
}
[Benchmark(Baseline = true)]
public void For()
{
for (var i = 0; i < _LENGTH; i++)
{
var x = i % _WIDTH;
var y = i / _HEIGHT;
var uv = new Vector2(x, y) / new Vector2(_WIDTH, _HEIGHT);
_buffers[i] = NoiseJobVector.GradientNoise(uv);
}
}
}