jemalloc.NET
jemalloc.NET copied to clipboard
Validate values computed for JEM buffers during benchmark
General design for a benchmark run over an array/buffer should be:
- Compute the baseline value using builtin .NET operators and methods from System.Math.
- Compute the value using JEM methods.
- In the cleanup phase after each benchmark iteration compare the JEM/builitin values for each element in the array and throw an exception if any don't match.
Added in 88c3c2b73430b6ba910512f5776c387bd2b0dd45. e.g for validating the array multiply benchmark:
int index = GM<T>.Rng.Next(0, ArraySize);
SafeArray<T> nativeArray = GetValue<SafeArray<T>>("nativeArray");
T[] managedArray = GetValue<T[]>("managedArray");
T mul = GetValue<T>("mul");
T fill = GetValue<T>("fill");
T val = GM<T>.Multiply(fill, mul);
if (!nativeArray[index].Equals(val))
{
Log.WriteLineError($"Native array at index {index} is {nativeArray[index]} not {val}.");
throw new Exception();
}
else if (!managedArray[index].Equals(val))
{
Log.WriteLineError($"Managed array at index {index} is {managedArray[index]} not {val}.");
throw new Exception();
}