public void UnsafeFastBufferCopy() { for (int i = 0; i < N; i++) { FastBuffer.UnsafeBlockCopy(bufferFrom, 0, bufferTo, 0, Size); } }
public unsafe static void BenchUnsafe() { var count = 10000000; var from = new byte[1024]; var to = new byte[1024]; var w = Stopwatch.StartNew(); fixed(byte *src = &from[0], dst = &to[0]) { byte *dt = dst; for (int n = 0; n < 100; n++) { for (int i = 0; i < count; i++) { FastBuffer.UnsafeBlockCopy(src, dst, n); } w.Stop(); Console.WriteLine($"FastBuffer.UnsafeBlockCopy {n}bytes cost:{w.ElapsedMilliseconds}"); w = Stopwatch.StartNew(); for (int i = 0; i < count; i++) { Buffer.MemoryCopy(src, dt, n, n); } w.Stop(); Console.WriteLine($"Buffer.MemoryCopy {n}bytes cost:{w.ElapsedMilliseconds}"); Console.WriteLine($"----------------------------{n}-------------------"); } } }
public unsafe void UnsafeFastBufferCopyFixed() { fixed(byte *src = &bufferFrom[0], dst = &bufferTo[0]) { for (int i = 0; i < N; i++) { FastBuffer.UnsafeBlockCopy(src, dst, Size); } } }
public unsafe static void WriteUnsafe(string name, char[] buffer, int position) { fixed (char* src = name, dst = &buffer[position]) FastBuffer.UnsafeBlockCopy((byte*)src, (byte*)dst, name.Length * 2); }
public unsafe static void WriteUnsafe(char* tsrc, char* tdst, int size) { FastBuffer.UnsafeBlockCopy((byte*)tsrc, (byte*)tdst, size); }