using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Diagnostics;
private static List<ArraySegment<byte>> _buffers = new List<ArraySegment<byte>>();
private static ArraySegment<byte> _buffer;
[StructLayout(LayoutKind.Explicit)]
private static ValBytes _valBytes = new ValBytes();
private static Memory<byte> data = new byte[8];
static void WriteLong(long v)
Span<byte> data = stackalloc byte[8];
MemoryMarshal.Write<long>(data, ref v);
static void WriteLongVal(long v)
_buffer[2] = _valBytes.B0;
_buffer[3] = _valBytes.B1;
_buffer[0] = _valBytes.B2;
_buffer[1] = _valBytes.B3;
_buffer[2] = _valBytes.B4;
_buffer[3] = _valBytes.B5;
_buffer[4] = _valBytes.B6;
_buffer[5] = _valBytes.B7;
_buffers.Add(new byte[8]);
int iterations = 10_000_000;
var watch = new Stopwatch();
for(int i = 0; i < iterations; ++i)
Console.WriteLine($"WriteLongVal elapsed: {watch.ElapsedMilliseconds}");
for(int i = 0; i < iterations; ++i)
Console.WriteLine($"WriteLong elapsed: {watch.ElapsedMilliseconds}");