Benchmarks mostly reorganized & cleaned up. Simplified for re-runs.

This commit is contained in:
mlemanczyk committed 2023-04-11 16:42:06 +02:00
1 parent eae5cb4452
commit 2d7e62df72
12 files changed
+2045 -1040

No files matched your search

@@ -0,0 +1,55 @@
using BenchmarkDotNet.Attributes;
using System.Buffers;
namespace Recyclable.Collections.Benchmarks.POC
{
public class ArraySizeLimitPocBenchmarks : PocBenchmarkBase
{
public static void Run()
{
var benchmark = new ArraySizeLimitPocBenchmarks();
benchmark.FindArraySizeLimit();
}
[Benchmark]
public void FindArraySizeLimit()
{
var pool = ArrayPool<object>.Shared;
var bufferSize = int.MaxValue;
var oldValue = 0;
while (true)
{
try
{
Console.WriteLine($"Allocating {bufferSize}");
var arr = pool.Rent((int)bufferSize);
var nextValue = (oldValue - bufferSize) >> 1;
if (nextValue == 0)
{
break;
}
oldValue = bufferSize;
bufferSize += nextValue;
pool.Return(arr);
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
}
catch (Exception)
{
Console.WriteLine($"Error during array creation when {nameof(bufferSize)} = {bufferSize}");
var nextValue = (oldValue - bufferSize) >> 1;
if (nextValue == 0)
{
break;
}
oldValue = bufferSize;
bufferSize -= nextValue;
}
}
Console.WriteLine("All done");
}
}
}