// [Benchmark(Description = "Marshal")] it blows up the whole system! public void AllocateWithMarshal() { var arrayPointer = Marshal.AllocHGlobal(SizeInBytes); DeadCodeEliminationHelper.KeepAliveWithoutBoxing(arrayPointer); // I am NOT freeing the memory on Purpose // why? because otherwise every other benchmark run will get the same block of memory // that was returned for the warmup run, and it would show that Marshall is 100x faster than new // Marshal.FreeHGlobal(arrayPointer); }
public async Task Dictionary_Allocate() { var tasks = new List <Task>(10); for (var i = 0; i < 10; i++) { tasks.Add(Task.Run(() => { for (var j = 0; j < 100; j++) { DeadCodeEliminationHelper.KeepAliveWithoutBoxing(FillDictionary(new Dictionary <string, string>(Size))); } })); } await Task.WhenAll(tasks); }
public void Allocate() => DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new byte[SizeInBytes]);
public void Allocate_New() { DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new byte[this.Size]); }
public void Task_Allocate() => DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new Task[Size]);
public void UseArray() { //Necessário dizer ao benchmark que não desejamos que os "dead codes" sejam eliminados DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new byte[Size]); }