in Sources/Runtime/Test.Psi/MemoryAccessPerf.cs [34:187]
public unsafe void BufferEx_Read_Managed_Perf()
{
var iterations = 100000;
var count = 256;
var bytes = new byte[count * 16];
int value = 1;
// warm-up
BufferEx.SizeOf<int>();
value = BufferEx.Read<int>(bytes, 0);
var sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
value = BufferEx.Read<int>(bytes, j);
}
}
sw.Stop();
Console.WriteLine("Read " + sw.ElapsedTicks);
var items = new int[256];
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
ReadBaseline(ref value, items, j);
}
}
sw.Stop();
Console.WriteLine("Read T from T[] baseline " + sw.ElapsedTicks);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
ReadBaseline(ref value, bytes, j);
}
}
sw.Stop();
Console.WriteLine("Read int baseline " + sw.ElapsedTicks);
var ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(256 * 16);
BufferEx.Read<int>(ptr);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
BufferEx.Read<int>(ptr + j);
}
}
sw.Stop();
Console.WriteLine("Read* " + sw.ElapsedTicks);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
ReadBaseline(ref value, ptr, j);
}
}
sw.Stop();
Console.WriteLine("Read* int baseline " + sw.ElapsedTicks);
var rgbValue = default(RGB);
BufferEx.Read<RGB>(bytes, 0);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
rgbValue = BufferEx.Read<RGB>(bytes, j);
}
}
sw.Stop();
Console.WriteLine("Read rgb " + sw.ElapsedTicks);
BufferEx.Read<RGB>(bytes, 0);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
BufferEx.Read<RGB>(bytes, j);
}
}
sw.Stop();
Console.WriteLine("Read ret rgb " + sw.ElapsedTicks);
BufferEx.Read<RGB>(ptr);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
BufferEx.Read<RGB>(ptr + j);
}
}
sw.Stop();
Console.WriteLine("Read* rgb" + sw.ElapsedTicks);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
ReadBaseline(ref rgbValue, bytes, j);
}
}
sw.Stop();
Console.WriteLine("Read rgb baseline " + sw.ElapsedTicks);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
ReadBaseline(ref rgbValue, ptr, j);
}
}
sw.Stop();
Console.WriteLine("Read* rgb baseline " + sw.ElapsedTicks);
ReadBaseline(ref rgbValue, bytes, 0, p => *(RGB*)p);
sw = Stopwatch.StartNew();
for (var i = 0; i < iterations; i++)
{
for (int j = 0; j < count; j++)
{
ReadBaseline(ref rgbValue, bytes, j, p => *(RGB*)p);
}
}
sw.Stop();
Console.WriteLine("Read rgb del baseline " + sw.ElapsedTicks);
}