Added new namespace `Misaki.HighPerformance.Image` for image processing, including classes for animated GIF handling and memory management. Added `AnimatedFrameResult` class for individual frames in animated images. Added `AnimatedGifEnumerator` class for enumerating frames in animated GIFs. Added `ColorComponents` enum for different color formats. Added `ImageInfo` struct for image dimensions and color components. Added `CRuntime` class for low-level memory management functions. Added `MemoryStats` class to track memory allocation statistics. Added utility functions for creating multi-dimensional arrays. Added new structures for fixed-size UTF-8 encoded strings. Added benchmarking classes to test new memory management features. Changed `StbImage.cs` to include new namespaces and functionality for image data manipulation. Changed project files to target .NET 9.0 and enable new features. Changed `Arena.cs` and `DynamicArena.cs` to use `nuint` for size parameters. Changed `BitSet.cs` to enhance bit manipulation methods. Changed `Program.cs` to run `FunctionPtrBenchmark` for performance testing. Removed memory tracking code from `AllocationManager.cs`, including the `_allocated` dictionary and related logic. Removed `Free` method from `IAllocator.cs` interface. Removed `UNSAFE_COLLECTION_CHECK` preprocessor directive from the codebase. Refactored various files to improve organization, moving from `Unsafe` to `LowLevel` namespace. Refactored `MemoryUtilities` class to include new memory operation methods. Refactored `UnsafeUtilities.cs` to support new collection structures.
57 lines
1.5 KiB
C#
57 lines
1.5 KiB
C#
using BenchmarkDotNet.Attributes;
|
|
using Misaki.HighPerformance.Jobs;
|
|
using Misaki.HighPerformance.LowLevel.Collections;
|
|
using Misaki.HighPerformance.Test.Jobs;
|
|
using System.Numerics;
|
|
|
|
namespace Misaki.HighPerformance.Test;
|
|
|
|
[MemoryDiagnoser]
|
|
public class ParallelNoiseBenchmark
|
|
{
|
|
private const int _WIDTH = 512;
|
|
private const int _HEIGHT = 512;
|
|
private const int _LENGTH = _WIDTH * _HEIGHT;
|
|
|
|
[Benchmark]
|
|
public static void JobSystem()
|
|
{
|
|
using var buffers = new UnsafeArray<float>(_LENGTH, Allocator.Persistent, AllocationOption.None);
|
|
var job = new NoiseJob()
|
|
{
|
|
buffers = buffers,
|
|
width = _WIDTH,
|
|
height = _HEIGHT
|
|
};
|
|
|
|
using var handle = job.Schedule(_LENGTH, 64);
|
|
handle.WaitComplete();
|
|
}
|
|
|
|
[Benchmark]
|
|
public static void ParallelFor()
|
|
{
|
|
using var buffers = new UnsafeArray<float>(_LENGTH, Allocator.Persistent, AllocationOption.None);
|
|
|
|
Parallel.For(0, _LENGTH, i =>
|
|
{
|
|
var x = i % _WIDTH;
|
|
var y = i / _HEIGHT;
|
|
var uv = new Vector2(x, y);
|
|
buffers[i] = NoiseJob.GradientNoise(uv);
|
|
});
|
|
}
|
|
|
|
[Benchmark]
|
|
public static void For()
|
|
{
|
|
using var buffers = new UnsafeArray<float>(_LENGTH, Allocator.Persistent, AllocationOption.None);
|
|
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);
|
|
}
|
|
}
|
|
} |