Refactor to use MHP_ENABLE_SAFETY_CHECKS, MHP_ENABLE_STACKTRACE, and MHP_ENABLE_MIMALLOC for feature toggling. Remove FreeList allocator in JobSchedular and debug-layer code, simplifying memory management. Improve memory leak detection and reporting, update memory allocation API, and guard all safety/debug features with new defines. Update csproj files, README, and code samples to match new API and toggles. Fix and improve collection types for correct behavior with and without safety checks. The codebase is now more modular and easier to configure for different build environments. BREAKING CHANGE: Old defines (ENABLE_SAFETY_CHECKS, ENABLE_DEBUG_LAYER, ENABLE_MIMALLOC) are replaced with MHP_* equivalents. FreeList allocator and related debug features are removed. Some APIs and behaviors have changed for safety/debug configuration.
93 lines
2.0 KiB
C#
93 lines
2.0 KiB
C#
using BenchmarkDotNet.Attributes;
|
|
using System.Numerics;
|
|
|
|
namespace Misaki.HighPerformance.Test.Benchmark;
|
|
|
|
public class HashCodeBenchmark
|
|
{
|
|
private struct Component
|
|
{
|
|
public int Value;
|
|
public int Value2;
|
|
public float Value3;
|
|
public Guid Value4;
|
|
public Matrix4x4 Value5;
|
|
public Vector4 Value6;
|
|
}
|
|
|
|
[Params(100, 1000, 10000)]
|
|
public int count;
|
|
|
|
private Component _component = new Component()
|
|
{
|
|
Value = 0,
|
|
Value2 = 1,
|
|
Value3 = 2,
|
|
Value4 = Guid.NewGuid(),
|
|
Value5 = Matrix4x4.Identity,
|
|
Value6 = Vector4.One
|
|
};
|
|
|
|
private Dictionary<Type, int> _hashCache = new();
|
|
//private UnsafeHashMap<Guid, int> _hashMap = new(16);
|
|
|
|
//~HashCodeBenchmark()
|
|
//{
|
|
// Dispose();
|
|
//}
|
|
|
|
[Benchmark]
|
|
public void Hash()
|
|
{
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
_ = _component.GetHashCode();
|
|
}
|
|
}
|
|
|
|
[Benchmark]
|
|
public void HashWithCache()
|
|
{
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
var type = typeof(Component);
|
|
if (!_hashCache.TryGetValue(type, out var hash))
|
|
{
|
|
hash = type.GetHashCode();
|
|
_hashCache[type] = hash;
|
|
}
|
|
|
|
_ = hash;
|
|
}
|
|
}
|
|
|
|
//[Benchmark]
|
|
//public void HashWithUnsafeHashMap()
|
|
//{
|
|
// for (var i = 0; i < count; i++)
|
|
// {
|
|
// var type = _component.GetType();
|
|
// var guid = type.GUID;
|
|
// if (!_hashMap.TryGetValue(guid, out var hash))
|
|
// {
|
|
// hash = type.GetHashCode();
|
|
// _hashMap.Add(guid, hash);
|
|
// _hashMap.Test(ref _hashMap._hashMap);
|
|
// }
|
|
|
|
// _ = hash;
|
|
// }
|
|
//}
|
|
|
|
//public void Dispose()
|
|
//{
|
|
// if (_disposed)
|
|
// {
|
|
// return;
|
|
// }
|
|
|
|
// _hashMap.Dispose();
|
|
|
|
// GC.SuppressFinalize(this);
|
|
//}
|
|
} |