Skip to content

Instantly share code, notes, and snippets.

@redknightlois
Created January 14, 2016 22:17
Show Gist options
  • Save redknightlois/2874ea1ce7a8b75e1779 to your computer and use it in GitHub Desktop.
Save redknightlois/2874ea1ce7a8b75e1779 to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BenchmarkDotNet.Samples.JIT
{
[BenchmarkTask(platform: BenchmarkPlatform.X64, jitVersion: BenchmarkJitVersion.RyuJit, warmupIterationCount: 1, targetIterationCount: 4, processCount: 1)]
public class Jit_StructCopy
{
public struct S2
{
public long A1;
public long A2;
}
public struct S4
{
public long A1;
public long A2;
public long A3;
public long A4;
}
public struct S8
{
public long A1;
public long A2;
public long A3;
public long A4;
public long A5;
public long A6;
public long A7;
public long A8;
}
private S2 src16;
private S2 dest16;
private S4 src32;
private S4 dest32;
private S8 src64;
private S8 dest64;
[Setup]
public void Setup ()
{
src16 = new S2 { A1 = 23, A2 = 45 };
src32 = new S4 { A1 = 23, A2 = 45, A3 = 311, A4 = 4122 };
src64 = new S8 { A1 = 23, A2 = 45, A3 = 311, A4 = 4122, A5 = 23, A6 = 45, A7 = 311, A8 = 4122 };
}
[Benchmark]
[OperationsPerInvoke(1)]
public S2 CopyStruct16Bytes()
{
dest16 = src16;
return dest16;
}
[Benchmark]
[OperationsPerInvoke(1)]
public S2 CopyProperties16Bytes()
{
dest16.A1 = src16.A1;
dest16.A2 = src16.A2;
return dest16;
}
[Benchmark]
[OperationsPerInvoke(1)]
public S4 CopyStruct32Bytes()
{
dest32 = src32;
return dest32;
}
[Benchmark]
[OperationsPerInvoke(1)]
public S4 CopyProperties32Bytes()
{
dest32.A1 = src32.A1;
dest32.A2 = src32.A2;
dest32.A3 = src32.A3;
dest32.A4 = src32.A4;
return dest32;
}
[Benchmark]
[OperationsPerInvoke(1)]
public S8 CopyStruct64Bytes()
{
dest64 = src64;
return dest64;
}
[Benchmark]
[OperationsPerInvoke(1)]
public S8 CopyProperties64Bytes()
{
dest64.A1 = src64.A1;
dest64.A2 = src64.A2;
dest64.A3 = src64.A3;
dest64.A4 = src64.A4;
dest64.A5 = src64.A5;
dest64.A6 = src64.A6;
dest64.A7 = src64.A7;
dest64.A8 = src64.A8;
return dest64;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment