// [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);
        }
Ejemplo n.º 3
0
 public void Allocate()
 => DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new byte[SizeInBytes]);
 public void Allocate_New()
 {
     DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new byte[this.Size]);
 }
Ejemplo n.º 5
0
 public void Task_Allocate()
 => DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new Task[Size]);
Ejemplo n.º 6
0
 public void UseArray()
 {
     //Necessário dizer ao benchmark que não desejamos que os "dead codes" sejam eliminados
     DeadCodeEliminationHelper.KeepAliveWithoutBoxing(new byte[Size]);
 }