Exemple #1
0
 public TestDefaultParams(
     sbyte sb          = -12,
     byte b            = 12,
     short s           = -1234,
     ushort us         = 1234,
     int i             = -12345,
     uint ui           = 12345,
     long l            = -12345678900L,
     ulong ul          = 12345678900UL,
     string str        = "str",
     float f           = 1.23f,
     double d          = 1.23,
     decimal dc        = 1.23M,
     bool bo           = true,
     TestEnum e        = TestEnum.Bar,
     UserScore complex = null)
 {
     B       = b;
     Sb      = sb;
     S       = s;
     Us      = us;
     I       = i;
     Ui      = ui;
     L       = l;
     Ul      = ul;
     Str     = str;
     F       = f;
     D       = d;
     Dc      = dc;
     Bo      = bo;
     E       = e;
     Complex = complex;
 }
Exemple #2
0
 public StructWithAllDefaults(
     byte b            = 12,
     sbyte sb          = -12,
     short s           = -1234,
     ushort us         = 1234,
     int i             = -12345,
     uint ui           = 12345,
     long l            = -12345678900L,
     ulong ul          = 12345678900UL,
     char c            = 'c',
     string str        = "str",
     float f           = 1.23f,
     double d          = 1.23,
     decimal dc        = 1.23M,
     bool bo           = true,
     TestEnum e        = TestEnum.Bar,
     UserScore complex = null,
     byte[] byteArray  = null,
     ArraySegment <byte> byteArraySegment = default(ArraySegment <byte>))
 {
     B                = b;
     Sb               = sb;
     S                = s;
     Us               = us;
     I                = i;
     Ui               = ui;
     L                = l;
     Ul               = ul;
     C                = c;
     Str              = str;
     F                = f;
     D                = d;
     Dc               = dc;
     Bo               = bo;
     E                = e;
     Complex          = complex;
     ByteArray        = byteArray;
     ByteArraySegment = byteArraySegment;
 }
Exemple #3
0
 public UserScoreWrapper(double weight, UserScore userScore)
 {
     Weight    = weight;
     UserScore = userScore;
 }
        public void SerialisationPerf()
        {
#if DEBUG
            Assert.True(false, "Performance comparison must be performed on a release build.");
#endif

            var dasherSer    = new Serialiser <UserScore>();
            var dasherPacker = new Packer(Stream.Null);

            var cliSer = MessagePackSerializer.Get <UserScore>(new SerializationContext
            {
                CompatibilityOptions =
                {
                    PackerCompatibilityOptions = PackerCompatibilityOptions.None
                },
                SerializationMethod = SerializationMethod.Map
            });
            var cliPacker = MsgPack.Packer.Create(Stream.Null, PackerCompatibilityOptions.None);

            var obj = new UserScore("Bob", 1234);

            const int warmUpLoopCount = 1000;
            const int timedLoopCount  = 10 * 1000 * 1000;

            var sw = Stopwatch.StartNew();

            ////

            for (var i = 0; i < warmUpLoopCount; i++)
            {
                cliSer.PackTo(cliPacker, obj);
            }

            TestUtils.CleanUpForPerfTest();

            sw.Restart();

            for (var i = 0; i < timedLoopCount; i++)
            {
                cliSer.PackTo(cliPacker, obj);
            }

            var cliMs = sw.Elapsed.TotalMilliseconds;

            ////

            for (var i = 0; i < warmUpLoopCount; i++)
            {
                dasherSer.Serialise(dasherPacker, obj);
                dasherPacker.Flush();
            }

            TestUtils.CleanUpForPerfTest();

            sw.Restart();

            for (var i = 0; i < timedLoopCount; i++)
            {
                dasherSer.Serialise(dasherPacker, obj);
                dasherPacker.Flush();
            }

            var dasherMs = sw.Elapsed.TotalMilliseconds;

            ////

            TestOutput.WriteLine($"{nameof(dasherMs)}={dasherMs} {nameof(cliMs)}={cliMs}");

            // serialisation performance is on par with MsgPack.Cli. should always be within 10%.
            Assert.True(dasherMs < cliMs * 1.1, $"{nameof(dasherMs)}={dasherMs} {nameof(cliMs)}={cliMs}");
        }