Пример #1
0
        public void DecodeLargeArray(int length, int count)
        {
            var builder = new StringBuilder();
            var random  = new Random();

            builder.Append("[");

            if (length > 0)
            {
                for (var i = 0;;)
                {
                    builder.Append(random.Next().ToString(CultureInfo.InvariantCulture));

                    if (++i >= length)
                    {
                        break;
                    }

                    builder.Append(",");
                }
            }

            builder.Append("]");

            var schema = new JSONSchema <long[]>();

            schema.DecoderDescriptor.HasElements(() => 0,
                                                 (ref long[] target, IEnumerable <long> elements) => target = elements.ToArray()).HasValue();

            var decoder = schema.CreateDecoder(Array.Empty <long>);

            CompareNewtonsoft.BenchDecode(decoder, builder.ToString(), count);
        }
Пример #2
0
        public void DecodeNestedArray()
        {
            const string source =
                "{" +
                "\"children\":[{" +
                "\"children\":[],\"value\":\"a\"" +
                "},{" +
                "\"children\":[{\"children\":[],\"value\":\"b\"},{\"children\":[],\"value\":\"c\"}]," +
                "\"value\":\"d\"" +
                "},{" +
                "\"children\":[],\"value\":\"e\"" +
                "}]," +
                "\"value\":\"f\"" +
                "}";

            var decoder = Linker.CreateDecoder(new JSONSchema <MyNestedArray>());

            CompareNewtonsoft.BenchDecode(decoder, source, 10000);
        }
Пример #3
0
        public void DecodeFlatStructure()
        {
            const string source = "{" +
                                  "\"lorem\":0," +
                                  "\"ipsum\":65464658634633," +
                                  "\"sit\":1.1," +
                                  "\"amet\":\"Hello, World!\"," +
                                  "\"consectetur\":255," +
                                  "\"adipiscing\":64," +
                                  "\"elit\":\"z\"," + "\"sed\":53.25," +
                                  "\"pulvinar\":\"I sense a soul in search of answers\"," +
                                  "\"fermentum\":6553," +
                                  "\"hendrerit\":-32768" +
                                  "}";

            var decoder = Linker.CreateDecoder(new JSONSchema <MyFlatStructure>());

            CompareNewtonsoft.BenchDecode(decoder, source, 10000);
        }
Пример #4
0
        public void EncodeFlatStructure()
        {
            var encoder  = Linker.CreateEncoder(new JSONSchema <MyFlatStructure>());
            var instance = new MyFlatStructure
            {
                adipiscing  = 64,
                amet        = "Hello, World!",
                consectetur = 255,
                elit        = 'z',
                fermentum   = 6553,
                hendrerit   = -32768,
                ipsum       = 65464658634633,
                lorem       = 0,
                pulvinar    = "I sense a soul in search of answers",
                sed         = 53.25f,
                sit         = 1.1
            };

            CompareNewtonsoft.BenchEncode(encoder, instance, 10000);
        }
Пример #5
0
        public void EncodeNestedArray()
        {
            var encoder  = Linker.CreateEncoder(new JSONSchema <MyNestedArray>());
            var instance = new MyNestedArray
            {
                children = new[]
                {
                    new MyNestedArray
                    {
                        children = null,
                        value    = "a"
                    },
                    new MyNestedArray
                    {
                        children = new[]
                        {
                            new MyNestedArray
                            {
                                children = null,
                                value    = "b"
                            },
                            new MyNestedArray
                            {
                                children = null,
                                value    = "c"
                            }
                        },
                        value = "d"
                    },
                    new MyNestedArray
                    {
                        children = new MyNestedArray[0],
                        value    = "e"
                    }
                },
                value = "f"
            };

            CompareNewtonsoft.BenchEncode(encoder, instance, 10000);
        }