using BenchmarkDotNet.Attributes; using System.Collections.Concurrent; using System.Runtime.CompilerServices; namespace Benchmarks.Console.Memory; [MemoryDiagnoser] public class MicroAllocating { #region Lifecycle private readonly ObjectPool _class8Pool; private readonly ObjectPool _class16Pool; private readonly ObjectPool _class24Pool; private readonly ObjectPool _class32Pool; private readonly ObjectPool _class40Pool; private readonly ObjectPool _class48Pool; private readonly ObjectPool _class56Pool; private readonly ObjectPool _class64Pool; private readonly ObjectPool _class72Pool; private readonly ObjectPool _class80Pool; private readonly ObjectPool _class88Pool; private readonly ObjectPool _class96Pool; public MicroAllocating() { _class8Pool = new ObjectPool(); _class16Pool = new ObjectPool(); _class24Pool = new ObjectPool(); _class32Pool = new ObjectPool(); _class40Pool = new ObjectPool(); _class48Pool = new ObjectPool(); _class56Pool = new ObjectPool(); _class64Pool = new ObjectPool(); _class72Pool = new ObjectPool(); _class80Pool = new ObjectPool(); _class88Pool = new ObjectPool(); _class96Pool = new ObjectPool(); InitializeObjectPool(_class8Pool); InitializeObjectPool(_class16Pool); InitializeObjectPool(_class24Pool); InitializeObjectPool(_class32Pool); InitializeObjectPool(_class40Pool); InitializeObjectPool(_class48Pool); InitializeObjectPool(_class56Pool); InitializeObjectPool(_class64Pool); InitializeObjectPool(_class72Pool); InitializeObjectPool(_class80Pool); InitializeObjectPool(_class88Pool); InitializeObjectPool(_class96Pool); } private static void InitializeObjectPool(ObjectPool objectPool) where T : IPoolable, new() { var item1 = objectPool.Rent(); var item2 = objectPool.Rent(); var item3 = objectPool.Rent(); objectPool.Return(item1); objectPool.Return(item2); objectPool.Return(item3); } #endregion #region Test Classes private class Class8 : IPoolable, IReadOnlyStruct8 { public long Number1 { get; set; } public void Reset() { Number1 = 0; } } private class Class16 : IPoolable, IReadOnlyStruct16 { public long Number1 { get; set; } public long Number2 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; } } private class Class24 : IPoolable, IReadOnlyStruct24 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; } } private class Class32 : IPoolable, IReadOnlyStruct32 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; } } private class Class40 : IPoolable, IReadOnlyStruct40 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; } } private class Class48 : IPoolable, IReadOnlyStruct48 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public long Number6 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; Number6 = 0; } } private class Class56 : IPoolable, IReadOnlyStruct56 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public long Number6 { get; set; } public long Number7 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; Number6 = 0; Number7 = 0; } } private class Class64 : IPoolable, IReadOnlyStruct64 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public long Number6 { get; set; } public long Number7 { get; set; } public long Number8 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; Number6 = 0; Number7 = 0; Number8 = 0; } } private class Class72 : IPoolable, IReadOnlyStruct72 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public long Number6 { get; set; } public long Number7 { get; set; } public long Number8 { get; set; } public long Number9 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; Number6 = 0; Number7 = 0; Number8 = 0; Number9 = 0; } } private class Class80 : IPoolable, IReadOnlyStruct80 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public long Number6 { get; set; } public long Number7 { get; set; } public long Number8 { get; set; } public long Number9 { get; set; } public long Number10 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; Number6 = 0; Number7 = 0; Number8 = 0; Number9 = 0; Number10 = 0; } } private class Class88 : IPoolable, IReadOnlyStruct88 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public long Number6 { get; set; } public long Number7 { get; set; } public long Number8 { get; set; } public long Number9 { get; set; } public long Number10 { get; set; } public long Number11 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; Number6 = 0; Number7 = 0; Number8 = 0; Number9 = 0; Number11 = 0; } } private class Class96 : IPoolable, IReadOnlyStruct96 { public long Number1 { get; set; } public long Number2 { get; set; } public long Number3 { get; set; } public long Number4 { get; set; } public long Number5 { get; set; } public long Number6 { get; set; } public long Number7 { get; set; } public long Number8 { get; set; } public long Number9 { get; set; } public long Number10 { get; set; } public long Number11 { get; set; } public long Number12 { get; set; } public void Reset() { Number1 = 0; Number2 = 0; Number3 = 0; Number4 = 0; Number5 = 0; Number6 = 0; Number7 = 0; Number8 = 0; Number9 = 0; Number11 = 0; Number12 = 0; } } #endregion #region Test Structs private struct Struct8 { public long Number1; } private struct Struct16 { public long Number1; public long Number2; } private struct Struct24 { public long Number1; public long Number2; public long Number3; } private struct Struct32 { public long Number1; public long Number2; public long Number3; public long Number4; } private struct Struct40 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; } private struct Struct48 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; public long Number6; } private struct Struct56 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; public long Number6; public long Number7; } private struct Struct64 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; public long Number6; public long Number7; public long Number8; } private struct Struct72 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; public long Number6; public long Number7; public long Number8; public long Number9; } private struct Struct80 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; public long Number6; public long Number7; public long Number8; public long Number9; public long Number10; } private struct Struct88 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; public long Number6; public long Number7; public long Number8; public long Number9; public long Number10; public long Number11; } private struct Struct96 { public long Number1; public long Number2; public long Number3; public long Number4; public long Number5; public long Number6; public long Number7; public long Number8; public long Number9; public long Number10; public long Number11; public long Number12; } #endregion #region Test ReadOnly Structs private readonly record struct ReadOnlyStruct8(long Number1) : IReadOnlyStruct8; private readonly record struct ReadOnlyStruct16(long Number1, long Number2) : IReadOnlyStruct16; private readonly record struct ReadOnlyStruct24(long Number1, long Number2, long Number3) : IReadOnlyStruct24; private readonly record struct ReadOnlyStruct32(long Number1, long Number2, long Number3, long Number4) : IReadOnlyStruct32; private readonly record struct ReadOnlyStruct40(long Number1, long Number2, long Number3, long Number4, long Number5) : IReadOnlyStruct40; private readonly record struct ReadOnlyStruct48(long Number1, long Number2, long Number3, long Number4, long Number5, long Number6) : IReadOnlyStruct48; private readonly record struct ReadOnlyStruct56(long Number1, long Number2, long Number3, long Number4, long Number5, long Number6, long Number7) : IReadOnlyStruct56; private readonly record struct ReadOnlyStruct64(long Number1, long Number2, long Number3, long Number4, long Number5, long Number6, long Number7, long Number8) : IReadOnlyStruct64; private readonly record struct ReadOnlyStruct72(long Number1, long Number2, long Number3, long Number4, long Number5, long Number6, long Number7, long Number8, long Number9) : IReadOnlyStruct72; private readonly record struct ReadOnlyStruct80(long Number1, long Number2, long Number3, long Number4, long Number5, long Number6, long Number7, long Number8, long Number9, long Number10) : IReadOnlyStruct80; private readonly record struct ReadOnlyStruct88(long Number1, long Number2, long Number3, long Number4, long Number5, long Number6, long Number7, long Number8, long Number9, long Number10, long Number11) : IReadOnlyStruct88; private readonly record struct ReadOnlyStruct96(long Number1, long Number2, long Number3, long Number4, long Number5, long Number6, long Number7, long Number8, long Number9, long Number10, long Number11, long Number12) : IReadOnlyStruct96; #endregion #region ReadOnly Struct Interfaces private interface IReadOnlyStruct8 { long Number1 { get; } } private interface IReadOnlyStruct16 { long Number1 { get; } long Number2 { get; } } private interface IReadOnlyStruct24 { long Number1 { get; } long Number2 { get; } long Number3 { get; } } private interface IReadOnlyStruct32 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } } private interface IReadOnlyStruct40 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } } private interface IReadOnlyStruct48 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } long Number6 { get; } } private interface IReadOnlyStruct56 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } long Number6 { get; } long Number7 { get; } } private interface IReadOnlyStruct64 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } long Number6 { get; } long Number7 { get; } long Number8 { get; } } private interface IReadOnlyStruct72 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } long Number6 { get; } long Number7 { get; } long Number8 { get; } long Number9 { get; } } private interface IReadOnlyStruct80 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } long Number6 { get; } long Number7 { get; } long Number8 { get; } long Number9 { get; } long Number10 { get; } } private interface IReadOnlyStruct88 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } long Number6 { get; } long Number7 { get; } long Number8 { get; } long Number9 { get; } long Number10 { get; } long Number11 { get; } } private interface IReadOnlyStruct96 { long Number1 { get; } long Number2 { get; } long Number3 { get; } long Number4 { get; } long Number5 { get; } long Number6 { get; } long Number7 { get; } long Number8 { get; } long Number9 { get; } long Number10 { get; } long Number11 { get; } long Number12 { get; } } #endregion #region Class Benchmark [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_8() { var request = new Class8 { Number1 = 1_000, }; var request2 = new Class8 { Number1 = 2_000, }; var request3 = new Class8 { Number1 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_16() { var request = new Class16 { Number1 = 1_000, Number2 = 1_000, }; var request2 = new Class16 { Number1 = 2_000, Number2 = 2_000, }; var request3 = new Class16 { Number1 = 3_000, Number2 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_24() { var request = new Class24 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, }; var request2 = new Class24 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, }; var request3 = new Class24 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_32() { var request = new Class32 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, }; var request2 = new Class32 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, }; var request3 = new Class32 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_40() { var request = new Class40 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, }; var request2 = new Class40 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, }; var request3 = new Class40 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_48() { var request = new Class48 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, }; var request2 = new Class48 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, }; var request3 = new Class48 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_56() { var request = new Class56 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, }; var request2 = new Class56 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, }; var request3 = new Class56 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_64() { var request = new Class64 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, }; var request2 = new Class64 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, }; var request3 = new Class64 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_72() { var request = new Class72 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, }; var request2 = new Class72 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, }; var request3 = new Class72 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_80() { var request = new Class80 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, }; var request2 = new Class80 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, }; var request3 = new Class80 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_88() { var request = new Class88 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, }; var request2 = new Class88 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, }; var request3 = new Class88 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClass_96() { var request = new Class96 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, Number12 = 1_000, }; var request2 = new Class96 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, Number12 = 2_000, }; var request3 = new Class96 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, Number12 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } #endregion #region Struct Benchmark [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_8() { var request = new Struct8 { Number1 = 1_000, }; var request2 = new Struct8 { Number1 = 2_000, }; var request3 = new Struct8 { Number1 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_16() { var request = new Struct16 { Number1 = 1_000, Number2 = 1_000, }; var request2 = new Struct16 { Number1 = 2_000, Number2 = 2_000, }; var request3 = new Struct16 { Number1 = 3_000, Number2 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_24() { var request = new Struct24 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, }; var request2 = new Struct24 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, }; var request3 = new Struct24 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_32() { var request = new Struct32 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, }; var request2 = new Struct32 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, }; var request3 = new Struct32 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_40() { var request = new Struct40 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, }; var request2 = new Struct40 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, }; var request3 = new Struct40 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_48() { var request = new Struct48 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, }; var request2 = new Struct48 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, }; var request3 = new Struct48 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_56() { var request = new Struct56 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, }; var request2 = new Struct56 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, }; var request3 = new Struct56 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_64() { var request = new Struct64 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, }; var request2 = new Struct64 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, }; var request3 = new Struct64 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_72() { var request = new Struct72 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, }; var request2 = new Struct72 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, }; var request3 = new Struct72 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_80() { var request = new Struct80 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, }; var request2 = new Struct80 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, }; var request3 = new Struct80 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_88() { var request = new Struct88 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, }; var request2 = new Struct88 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, }; var request3 = new Struct88 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStruct_96() { var request = new Struct96 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, Number12 = 1_000, }; var request2 = new Struct96 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, Number12 = 2_000, }; var request3 = new Struct96 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, Number12 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } #endregion #region Struct By Ref Benchmark [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_8() { var request = new Struct8 { Number1 = 1_000, }; var request2 = new Struct8 { Number1 = 2_000, }; var request3 = new Struct8 { Number1 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_16() { var request = new Struct16 { Number1 = 1_000, Number2 = 1_000, }; var request2 = new Struct16 { Number1 = 2_000, Number2 = 2_000, }; var request3 = new Struct16 { Number1 = 3_000, Number2 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_24() { var request = new Struct24 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, }; var request2 = new Struct24 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, }; var request3 = new Struct24 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_32() { var request = new Struct32 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, }; var request2 = new Struct32 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, }; var request3 = new Struct32 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_40() { var request = new Struct40 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, }; var request2 = new Struct40 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, }; var request3 = new Struct40 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_48() { var request = new Struct48 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, }; var request2 = new Struct48 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, }; var request3 = new Struct48 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_56() { var request = new Struct56 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, }; var request2 = new Struct56 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, }; var request3 = new Struct56 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_64() { var request = new Struct64 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, }; var request2 = new Struct64 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, }; var request3 = new Struct64 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_72() { var request = new Struct72 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, }; var request2 = new Struct72 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, }; var request3 = new Struct72 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_80() { var request = new Struct80 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, }; var request2 = new Struct80 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, }; var request3 = new Struct80 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_88() { var request = new Struct88 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, }; var request2 = new Struct88 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, }; var request3 = new Struct88 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoStructByRef_96() { var request = new Struct96 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, Number12 = 1_000, }; var request2 = new Struct96 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, Number12 = 2_000, }; var request3 = new Struct96 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, Number12 = 3_000, }; Sum(in request, in request2, in request3); Sum(in request, in request2, in request3); } #endregion #region ReadOnlyStruct Benchmark [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_8() { var request = new ReadOnlyStruct8 { Number1 = 1_000, }; var request2 = new ReadOnlyStruct8 { Number1 = 2_000, }; var request3 = new ReadOnlyStruct8 { Number1 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_16() { var request = new ReadOnlyStruct16 { Number1 = 1_000, Number2 = 1_000, }; var request2 = new ReadOnlyStruct16 { Number1 = 2_000, Number2 = 2_000, }; var request3 = new ReadOnlyStruct16 { Number1 = 3_000, Number2 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_24() { var request = new ReadOnlyStruct24 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, }; var request2 = new ReadOnlyStruct24 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, }; var request3 = new ReadOnlyStruct24 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_32() { var request = new ReadOnlyStruct32 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, }; var request2 = new ReadOnlyStruct32 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, }; var request3 = new ReadOnlyStruct32 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_40() { var request = new ReadOnlyStruct40 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, }; var request2 = new ReadOnlyStruct40 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, }; var request3 = new ReadOnlyStruct40 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_48() { var request = new ReadOnlyStruct48 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, }; var request2 = new ReadOnlyStruct48 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, }; var request3 = new ReadOnlyStruct48 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_56() { var request = new ReadOnlyStruct56 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, }; var request2 = new ReadOnlyStruct56 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, }; var request3 = new ReadOnlyStruct56 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_64() { var request = new ReadOnlyStruct64 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, }; var request2 = new ReadOnlyStruct64 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, }; var request3 = new ReadOnlyStruct64 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_72() { var request = new ReadOnlyStruct72 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, }; var request2 = new ReadOnlyStruct72 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, }; var request3 = new ReadOnlyStruct72 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_80() { var request = new ReadOnlyStruct80 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, }; var request2 = new ReadOnlyStruct80 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, }; var request3 = new ReadOnlyStruct80 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_88() { var request = new ReadOnlyStruct88 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, }; var request2 = new ReadOnlyStruct88 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, }; var request3 = new ReadOnlyStruct88 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoReadOnlyStruct_96() { var request = new ReadOnlyStruct96 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, Number12 = 1_000, }; var request2 = new ReadOnlyStruct96 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, Number12 = 2_000, }; var request3 = new ReadOnlyStruct96 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, Number12 = 3_000, }; Sum(request, request2, request3); Sum(request, request2, request3); } #endregion #region Struct as IReadOnlyStruct Benchmark [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_8() { var request = new ReadOnlyStruct8 { Number1 = 1_000, }; var request2 = new ReadOnlyStruct8 { Number1 = 2_000, }; var request3 = new ReadOnlyStruct8 { Number1 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_16() { var request = new ReadOnlyStruct16 { Number1 = 1_000, Number2 = 1_000, }; var request2 = new ReadOnlyStruct16 { Number1 = 2_000, Number2 = 2_000, }; var request3 = new ReadOnlyStruct16 { Number1 = 3_000, Number2 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_24() { var request = new ReadOnlyStruct24 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, }; var request2 = new ReadOnlyStruct24 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, }; var request3 = new ReadOnlyStruct24 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_32() { var request = new ReadOnlyStruct32 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, }; var request2 = new ReadOnlyStruct32 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, }; var request3 = new ReadOnlyStruct32 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_40() { var request = new ReadOnlyStruct40 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, }; var request2 = new ReadOnlyStruct40 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, }; var request3 = new ReadOnlyStruct40 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_48() { var request = new ReadOnlyStruct48 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, }; var request2 = new ReadOnlyStruct48 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, }; var request3 = new ReadOnlyStruct48 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_56() { var request = new ReadOnlyStruct56 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, }; var request2 = new ReadOnlyStruct56 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, }; var request3 = new ReadOnlyStruct56 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_64() { var request = new ReadOnlyStruct64 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, }; var request2 = new ReadOnlyStruct64 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, }; var request3 = new ReadOnlyStruct64 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_72() { var request = new ReadOnlyStruct72 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, }; var request2 = new ReadOnlyStruct72 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, }; var request3 = new ReadOnlyStruct72 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_80() { var request = new ReadOnlyStruct80 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, }; var request2 = new ReadOnlyStruct80 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, }; var request3 = new ReadOnlyStruct80 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_88() { var request = new ReadOnlyStruct88 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, }; var request2 = new ReadOnlyStruct88 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, }; var request3 = new ReadOnlyStruct88 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoIReadOnlyStruct_96() { var request = new ReadOnlyStruct96 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, Number12 = 1_000, }; var request2 = new ReadOnlyStruct96 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, Number12 = 2_000, }; var request3 = new ReadOnlyStruct96 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, Number12 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } #endregion #region Class as IReadOnlyStruct Benchmark [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_8() { var request = new Class8 { Number1 = 1_000, }; var request2 = new Class8 { Number1 = 2_000, }; var request3 = new Class8 { Number1 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_16() { var request = new Class16 { Number1 = 1_000, Number2 = 1_000, }; var request2 = new Class16 { Number1 = 2_000, Number2 = 2_000, }; var request3 = new Class16 { Number1 = 3_000, Number2 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_24() { var request = new Class24 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, }; var request2 = new Class24 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, }; var request3 = new Class24 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_32() { var request = new Class32 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, }; var request2 = new Class32 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, }; var request3 = new Class32 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_40() { var request = new Class40 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, }; var request2 = new Class40 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, }; var request3 = new Class40 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_48() { var request = new Class48 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, }; var request2 = new Class48 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, }; var request3 = new Class48 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_56() { var request = new Class56 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, }; var request2 = new Class56 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, }; var request3 = new Class56 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_64() { var request = new Class64 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, }; var request2 = new Class64 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, }; var request3 = new Class64 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_72() { var request = new Class72 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, }; var request2 = new Class72 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, }; var request3 = new Class72 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_80() { var request = new Class80 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, }; var request2 = new Class80 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, }; var request3 = new Class80 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_88() { var request = new Class88 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, }; var request2 = new Class88 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, }; var request3 = new Class88 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassAsInterface_96() { var request = new Class96 { Number1 = 1_000, Number2 = 1_000, Number3 = 1_000, Number4 = 1_000, Number5 = 1_000, Number6 = 1_000, Number7 = 1_000, Number8 = 1_000, Number9 = 1_000, Number10 = 1_000, Number11 = 1_000, Number12 = 1_000, }; var request2 = new Class96 { Number1 = 2_000, Number2 = 2_000, Number3 = 2_000, Number4 = 2_000, Number5 = 2_000, Number6 = 2_000, Number7 = 2_000, Number8 = 2_000, Number9 = 2_000, Number10 = 2_000, Number11 = 2_000, Number12 = 2_000, }; var request3 = new Class96 { Number1 = 3_000, Number2 = 3_000, Number3 = 3_000, Number4 = 3_000, Number5 = 3_000, Number6 = 3_000, Number7 = 3_000, Number8 = 3_000, Number9 = 3_000, Number10 = 3_000, Number11 = 3_000, Number12 = 3_000, }; SumI(request, request2, request3); SumI(request, request2, request3); } #endregion #region Class From Pool Benchmark [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_8() { var request = _class8Pool.Rent(); request.Number1 = 1_000; var request2 = _class8Pool.Rent(); request2.Number1 = 2_000; var request3 = _class8Pool.Rent(); request3.Number1 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_16() { var request = _class16Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; var request2 = _class16Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; var request3 = _class16Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_24() { var request = _class24Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; var request2 = _class24Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; var request3 = _class24Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_32() { var request = _class32Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; var request2 = _class32Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; var request3 = _class32Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_40() { var request = _class40Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; var request2 = _class40Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; var request3 = _class40Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_48() { var request = _class48Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; request.Number6 = 1_000; var request2 = _class48Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; request2.Number6 = 2_000; var request3 = _class48Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; request3.Number6 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_56() { var request = _class56Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; request.Number6 = 1_000; request.Number7 = 1_000; var request2 = _class56Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; request2.Number6 = 2_000; request2.Number7 = 2_000; var request3 = _class56Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; request3.Number6 = 3_000; request3.Number7 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_64() { var request = _class64Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; request.Number6 = 1_000; request.Number7 = 1_000; request.Number8 = 1_000; var request2 = _class64Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; request2.Number6 = 2_000; request2.Number7 = 2_000; request2.Number8 = 2_000; var request3 = _class64Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; request3.Number6 = 3_000; request3.Number7 = 3_000; request3.Number8 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_72() { var request = _class72Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; request.Number6 = 1_000; request.Number7 = 1_000; request.Number8 = 1_000; request.Number9 = 1_000; var request2 = _class72Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; request2.Number6 = 2_000; request2.Number7 = 2_000; request2.Number8 = 2_000; request2.Number9 = 2_000; var request3 = _class72Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; request3.Number6 = 3_000; request3.Number7 = 3_000; request3.Number8 = 3_000; request3.Number9 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_80() { var request = _class80Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; request.Number6 = 1_000; request.Number7 = 1_000; request.Number8 = 1_000; request.Number9 = 1_000; request.Number10 = 1_000; var request2 = _class80Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; request2.Number6 = 2_000; request2.Number7 = 2_000; request2.Number8 = 2_000; request2.Number9 = 2_000; request2.Number10 = 2_000; var request3 = _class80Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; request3.Number6 = 3_000; request3.Number7 = 3_000; request3.Number8 = 3_000; request3.Number9 = 3_000; request3.Number10 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_88() { var request = _class88Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; request.Number6 = 1_000; request.Number7 = 1_000; request.Number8 = 1_000; request.Number9 = 1_000; request.Number10 = 1_000; request.Number11 = 1_000; var request2 = _class88Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; request2.Number6 = 2_000; request2.Number7 = 2_000; request2.Number8 = 2_000; request2.Number9 = 2_000; request2.Number10 = 2_000; request2.Number11 = 2_000; var request3 = _class88Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; request3.Number6 = 3_000; request3.Number7 = 3_000; request3.Number8 = 3_000; request3.Number9 = 3_000; request3.Number10 = 3_000; request3.Number11 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } [Benchmark] [MethodImpl(MethodImplOptions.AggressiveOptimization)] public void PocoClassFromPool_96() { var request = _class96Pool.Rent(); request.Number1 = 1_000; request.Number2 = 1_000; request.Number3 = 1_000; request.Number4 = 1_000; request.Number5 = 1_000; request.Number6 = 1_000; request.Number7 = 1_000; request.Number8 = 1_000; request.Number9 = 1_000; request.Number10 = 1_000; request.Number11 = 1_000; request.Number12 = 1_000; var request2 = _class96Pool.Rent(); request2.Number1 = 2_000; request2.Number2 = 2_000; request2.Number3 = 2_000; request2.Number4 = 2_000; request2.Number5 = 2_000; request2.Number6 = 2_000; request2.Number7 = 2_000; request2.Number8 = 2_000; request2.Number9 = 2_000; request2.Number10 = 2_000; request2.Number11 = 2_000; request2.Number12 = 2_000; var request3 = _class96Pool.Rent(); request3.Number1 = 3_000; request3.Number2 = 3_000; request3.Number3 = 3_000; request3.Number4 = 3_000; request3.Number5 = 3_000; request3.Number6 = 3_000; request3.Number7 = 3_000; request3.Number8 = 3_000; request3.Number9 = 3_000; request3.Number10 = 3_000; request3.Number11 = 3_000; request3.Number12 = 3_000; Sum(request, request2, request3); Sum(request, request2, request3); } #endregion #region Dummy methods #region Class [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class8 request, Class8 request2, Class8 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class16 request, Class16 request2, Class16 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class24 request, Class24 request2, Class24 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class32 request, Class32 request2, Class32 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class40 request, Class40 request2, Class40 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class48 request, Class48 request2, Class48 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class56 request, Class56 request2, Class56 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class64 request, Class64 request2, Class64 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class72 request, Class72 request2, Class72 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class80 request, Class80 request2, Class80 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class88 request, Class88 request2, Class88 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Class96 request, Class96 request2, Class96 request3) => request.Number1 + request2.Number1 + request3.Number1; #endregion #region Struct [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct8 request, Struct8 request2, Struct8 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct16 request, Struct16 request2, Struct16 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct24 request, Struct24 request2, Struct24 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct32 request, Struct32 request2, Struct32 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct40 request, Struct40 request2, Struct40 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct48 request, Struct48 request2, Struct48 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct56 request, Struct56 request2, Struct56 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct64 request, Struct64 request2, Struct64 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct72 request, Struct72 request2, Struct72 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct80 request, Struct80 request2, Struct80 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct88 request, Struct88 request2, Struct88 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(Struct96 request, Struct96 request2, Struct96 request3) => request.Number1 + request2.Number1 + request3.Number1; #endregion #region Struct ByRef [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct8 request, in Struct8 request2, in Struct8 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct16 request, in Struct16 request2, in Struct16 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct24 request, in Struct24 request2, in Struct24 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct32 request, in Struct32 request2, in Struct32 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct40 request, in Struct40 request2, in Struct40 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct48 request, in Struct48 request2, in Struct48 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct56 request, in Struct56 request2, in Struct56 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct64 request, in Struct64 request2, in Struct64 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct72 request, in Struct72 request2, in Struct72 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct80 request, in Struct80 request2, in Struct80 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct88 request, in Struct88 request2, in Struct88 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(in Struct96 request, in Struct96 request2, in Struct96 request3) => request.Number1 + request2.Number1 + request3.Number1; #endregion #region ReadOnlyStruct [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct8 request, ReadOnlyStruct8 request2, ReadOnlyStruct8 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct16 request, ReadOnlyStruct16 request2, ReadOnlyStruct16 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct24 request, ReadOnlyStruct24 request2, ReadOnlyStruct24 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct32 request, ReadOnlyStruct32 request2, ReadOnlyStruct32 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct40 request, ReadOnlyStruct40 request2, ReadOnlyStruct40 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct48 request, ReadOnlyStruct48 request2, ReadOnlyStruct48 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct56 request, ReadOnlyStruct56 request2, ReadOnlyStruct56 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct64 request, ReadOnlyStruct64 request2, ReadOnlyStruct64 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct72 request, ReadOnlyStruct72 request2, ReadOnlyStruct72 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct80 request, ReadOnlyStruct80 request2, ReadOnlyStruct80 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct88 request, ReadOnlyStruct88 request2, ReadOnlyStruct88 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long Sum(ReadOnlyStruct96 request, ReadOnlyStruct96 request2, ReadOnlyStruct96 request3) => request.Number1 + request2.Number1 + request3.Number1; #endregion #region IReadOnlyStruct [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct8 request, IReadOnlyStruct8 request2, IReadOnlyStruct8 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct16 request, IReadOnlyStruct16 request2, IReadOnlyStruct16 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct24 request, IReadOnlyStruct24 request2, IReadOnlyStruct24 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct32 request, IReadOnlyStruct32 request2, IReadOnlyStruct32 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct40 request, IReadOnlyStruct40 request2, IReadOnlyStruct40 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct48 request, IReadOnlyStruct48 request2, IReadOnlyStruct48 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct56 request, IReadOnlyStruct56 request2, IReadOnlyStruct56 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct64 request, IReadOnlyStruct64 request2, IReadOnlyStruct64 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct72 request, IReadOnlyStruct72 request2, IReadOnlyStruct72 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct80 request, IReadOnlyStruct80 request2, IReadOnlyStruct80 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct88 request, IReadOnlyStruct88 request2, IReadOnlyStruct88 request3) => request.Number1 + request2.Number1 + request3.Number1; [MethodImpl(MethodImplOptions.NoInlining)] private long SumI(IReadOnlyStruct96 request, IReadOnlyStruct96 request2, IReadOnlyStruct96 request3) => request.Number1 + request2.Number1 + request3.Number1; #endregion #endregion } public interface IPoolable { void Reset(); } public class ObjectPool where T : IPoolable, new() { private readonly ConcurrentStack _pool; public ObjectPool() { _pool = new ConcurrentStack(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public T Rent() { if (!_pool.TryPop(out var item)) { return new T(); } return item; } public void Return(T member) { member.Reset(); _pool.Push(member); } }