Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
struct in引数戦略のパフォーマンス確認
BenchmarkDotNet=v0.10.14, OS=Windows 10.0.16299.492 (1709/FallCreatorsUpdate/Redstone3)
Intel Core i7-6700 CPU 3.40GHz (Skylake), 1 CPU, 8 logical and 4 physical cores
Frequency=3328127 Hz, Resolution=300.4693 ns, Timer=TSC
.NET Core SDK=2.1.300
  [Host] : .NET Core 2.1.0 (CoreCLR 4.6.26515.07, CoreFX 4.6.26515.06), 64bit RyuJIT
  Clr    : .NET Framework 4.7.1 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2671.0
  Core   : .NET Core 2.1.0 (CoreCLR 4.6.26515.07, CoreFX 4.6.26515.06), 64bit RyuJIT

Method Job Runtime Mean Error StdDev Min Max Allocated
Size4NormalCall Clr Clr 1.192 ns 0.0085 ns 0.0066 ns 1.182 ns 1.204 ns 0 B
Size4InCall Clr Clr 1.388 ns 0.0111 ns 0.0104 ns 1.373 ns 1.406 ns 0 B
Size16NormalCall Clr Clr 1.542 ns 0.0063 ns 0.0052 ns 1.534 ns 1.552 ns 0 B
Size16InCall Clr Clr 1.349 ns 0.0109 ns 0.0102 ns 1.333 ns 1.369 ns 0 B
Size32NormalCall Clr Clr 9.474 ns 0.0689 ns 0.0644 ns 9.357 ns 9.564 ns 0 B
Size32InCall Clr Clr 9.460 ns 0.0807 ns 0.0755 ns 9.320 ns 9.563 ns 0 B
Size64NormalCall Clr Clr 9.895 ns 0.1095 ns 0.1024 ns 9.733 ns 10.073 ns 0 B
Size64InCall Clr Clr 9.404 ns 0.0368 ns 0.0344 ns 9.353 ns 9.478 ns 0 B
Size128NormalCall Clr Clr 14.629 ns 0.1486 ns 0.1317 ns 14.444 ns 14.878 ns 0 B
Size128InCall Clr Clr 9.742 ns 0.0180 ns 0.0159 ns 9.710 ns 9.773 ns 0 B
Size256NormalCall Clr Clr 27.666 ns 0.1301 ns 0.1086 ns 27.378 ns 27.802 ns 0 B
Size256InCall Clr Clr 18.479 ns 0.0789 ns 0.0659 ns 18.339 ns 18.608 ns 0 B
Size4NormalCall Core Core 1.399 ns 0.0131 ns 0.0117 ns 1.384 ns 1.421 ns 0 B
Size4InCall Core Core 1.187 ns 0.0081 ns 0.0063 ns 1.178 ns 1.198 ns 0 B
Size16NormalCall Core Core 1.608 ns 0.0234 ns 0.0219 ns 1.572 ns 1.652 ns 0 B
Size16InCall Core Core 1.675 ns 0.0145 ns 0.0136 ns 1.652 ns 1.699 ns 0 B
Size32NormalCall Core Core 9.440 ns 0.0798 ns 0.0747 ns 9.360 ns 9.594 ns 0 B
Size32InCall Core Core 9.131 ns 0.0931 ns 0.0871 ns 8.972 ns 9.250 ns 0 B
Size64NormalCall Core Core 9.857 ns 0.0831 ns 0.0777 ns 9.717 ns 9.944 ns 0 B
Size64InCall Core Core 9.299 ns 0.0818 ns 0.0766 ns 9.172 ns 9.410 ns 0 B
Size128NormalCall Core Core 13.396 ns 0.0409 ns 0.0363 ns 13.329 ns 13.449 ns 0 B
Size128InCall Core Core 9.539 ns 0.0278 ns 0.0247 ns 9.508 ns 9.584 ns 0 B
Size256NormalCall Core Core 22.155 ns 0.1241 ns 0.1100 ns 21.949 ns 22.337 ns 0 B
Size256InCall Core Core 14.843 ns 0.1388 ns 0.1298 ns 14.615 ns 15.044 ns 0 B
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Columns;
using BenchmarkDotNet.Attributes.Jobs;
using System.Runtime.CompilerServices;
namespace Bench
{
[ClrJob, CoreJob]
[MeanColumn, MinColumn, MaxColumn]
[MemoryDiagnoser]
public class StructBench
{
readonly struct Size4
{
public readonly int A;
}
readonly struct Size16
{
public readonly int A, B, C, D;
}
readonly struct Size32
{
public readonly Size16 A, B;
}
readonly struct Size64
{
public readonly Size32 A, B;
}
readonly struct Size128
{
public readonly Size64 A, B;
}
readonly struct Size256
{
public readonly Size128 A, B;
}
[Benchmark]
public int Size4NormalCall()
{
Size4 v = default;
return size4(v);
}
[Benchmark]
public int Size4InCall()
{
Size4 v = default;
return size4(in v);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size4(Size4 size4)
{
return size4.A;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size4(in Size4 size4)
{
return size4.A;
}
[Benchmark]
public int Size16NormalCall()
{
Size16 v = default;
return size16(v);
}
[Benchmark]
public int Size16InCall()
{
Size16 v = default;
return size16(in v);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size16(Size16 size16)
{
return size16.A;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size16(in Size16 size16)
{
return size16.A;
}
[Benchmark]
public int Size32NormalCall()
{
Size32 v = default;
return size32(v);
}
[Benchmark]
public int Size32InCall()
{
Size32 v = default;
return size32(in v);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size32(Size32 size32)
{
return size32.A.A;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size32(in Size32 size32)
{
return size32.A.A;
}
[Benchmark]
public int Size64NormalCall()
{
Size64 v = default;
return size64(v);
}
[Benchmark]
public int Size64InCall()
{
Size64 v = default;
return size64(in v);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size64(Size64 size64)
{
return size64.A.A.A;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size64(in Size64 size64)
{
return size64.A.A.A;
}
[Benchmark]
public int Size128NormalCall()
{
Size128 v = default;
return size128(v);
}
[Benchmark]
public int Size128InCall()
{
Size128 v = default;
return size128(in v);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size128(Size128 size128)
{
return size128.A.A.A.A;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size128(in Size128 size128)
{
return size128.A.A.A.A;
}
[Benchmark]
public int Size256NormalCall()
{
Size256 v = default;
return size256(v);
}
[Benchmark]
public int Size256InCall()
{
Size256 v = default;
return size256(in v);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size256(Size256 size256)
{
return size256.A.A.A.A.A;
}
[MethodImpl(MethodImplOptions.NoInlining)]
private int size256(in Size256 size256)
{
return size256.A.A.A.A.A;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.