using BenchmarkDotNet.Running; using BenchmarkDotNet.Attributes; using System.Runtime.InteropServices; using System.Reflection; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BenchmarkDotNet.Jobs; using Microsoft.Diagnostics.Tracing.Parsers.Clr; namespace BenchMark { public static class Program { static void Main(string[] args) { var summary = BenchmarkRunner.Run(); } } [SimpleJob(launchCount: 2, warmupCount: 2, iterationCount: 2)] public unsafe class BenchmarkClass { [Benchmark] public void HandleCalc() { int[] array = new int[4]; IntPtr ptr = GCHandle.Alloc(array).AddrOfPinnedObject(); } [Benchmark] public void MemCalc() { int[] array = new int[4]; Memory memory = new Memory(array); void* ptr = memory.Pin().Pointer; } } }