Exemplo n.º 1
0
        public void SerializeDeserialize_Int32_Neg1000_1000()
        {
            var lw = new LightWeight();

            for (var input = -10000; input < 10000; input++)
            {
                var encoded = lw.Encode(input);

                var output = lw.Decode <Int32>(encoded);
                Assert.Equal(input, output);
            }
        }
Exemplo n.º 2
0
        private static void Main(String[] args)
        {
            var runs       = 5;
            var iterations = 25;

            // Open test data (Book => Chapter => Verse => Content)
            var bible = JsonConvert.DeserializeObject <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(File.ReadAllText("esv.json"));

            // Do a number of runs
            for (var run = 0; run < runs; run++)
            {
                // Start timer
                var timer = Stopwatch.StartNew();

                // Start LightWeight
                var lw = new LightWeight();

                for (var itr = 0; itr < 25; itr++)
                {
                    // Encode
                    var output = lw.Encode(bible);

                    // Decode
                    lw.Decode <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(output);
                }

                Console.WriteLine($"{iterations} iterations in {timer.ElapsedMilliseconds}ms");
            }


            //  4-Feb-19 5984ms
            //  8-Feb-19 7201ms
            //  9-Feb-19 5977ms - Added VLQ encoding cache
            // 28-Feb-19 6023ms - No change
            // 28-Feb-19 5845ms - Swapped to using ArraySegment during encoding
            // 28-Feb-19 5128ms - Moved to struct-based nodes
            //  1-Mar-19 5015ms - Remove list in Node
            //  2-Mar-19 4827ms - Removed Stream for decoding, saving a heap of copying
            //  2-Mar-19 4725ms - Swapped from using Stream for encoding, saving some array resizing.
        }
Exemplo n.º 3
0
        /* 5-Feb-19
         * FORMAT      SIZE   SERIALIZE    DESERIALIZE
         *              JSON:      4,062KB   143ms    84ms
         *              ProtoBuff: 4,024KB   239ms    84ms
         *              MsgPack:   3,905KB   109ms    90ms
         *              LW:        3,918KB   182ms   179ms
         */
        /* 8-Feb-19 Improved algorithm (header-less where possible)
         * FORMAT      SIZE   SERIALIZE    DESERIALIZE
         *              JSON:      4,062KB   115ms    91ms
         *              ProtoBuff: 4,024KB   207ms    74ms
         *              MsgPack:   3,905KB   111ms    52ms
         *              LW:        3,886KB   244ms    90ms
         */
        /* 9-Feb-19 Added VLQ encoding cache
         *       FORMAT      SIZE   SERIALIZE    DESERIALIZE
         *              JSON:      4,062KB    82ms    50ms
         *              ProtoBuff: 4,024KB   240ms    53ms
         *              MsgPack:   3,905KB   164ms    59ms
         *              LW:        3,886KB   201ms   140ms
         */

        private static void Main(String[] args)
        {
            // Open test data (Book => Chapter => Verse => Content)
            var bible = JsonConvert.DeserializeObject <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(File.ReadAllText("esv.json"));


            Byte[] pbOutput;
            var    pbSerialize = Stopwatch.StartNew();

            pbOutput = new ProtobufCommonSerializer().SerializeToByteArray(bible);
            pbSerialize.Stop();
            var pbDeserialize = Stopwatch.StartNew();
            var pbResult      = new ProtobufCommonSerializer().Deserialize <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(new MemoryStream(pbOutput));

            if (pbResult.Count != bible.Count)
            {
                Console.WriteLine("ProtoBuff DISQUALIFIED");
            }

            pbDeserialize.Stop();


            Byte[] mpOutput;
            var    mpSerialize = Stopwatch.StartNew();

            mpOutput = new MsgPackCommonSerializer().SerializeToByteArray(bible);
            mpSerialize.Stop();
            var mpDeserialize = Stopwatch.StartNew();
            var mpResult      = new MsgPackCommonSerializer().Deserialize <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(new MemoryStream(mpOutput));

            if (mpResult.Count != bible.Count)
            {
                Console.WriteLine("MsgPack DISQUALIFIED");
            }

            mpDeserialize.Stop();

            String nsOutput;
            var    nsSerialize = Stopwatch.StartNew();

            nsOutput = JsonConvert.SerializeObject(bible);
            nsSerialize.Stop();
            var nsDeserialize = Stopwatch.StartNew();
            var nsResult      = JsonConvert.DeserializeObject <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(nsOutput);

            if (nsResult.Count != bible.Count)
            {
                Console.WriteLine("Json DISQUALIFIED");
            }

            nsDeserialize.Stop();

            var lw = new LightWeight();

            lw.PrepareFor <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(); // Cheating? Not sure.
            var lwSerialize = Stopwatch.StartNew();
            var lwOutput    = lw.Encode(bible);

            lwSerialize.Stop();
            var lwDeserialize = Stopwatch.StartNew();
            var lwResult      = lw.Decode <Dictionary <String, Dictionary <Int32, Dictionary <Int32, String> > > >(lwOutput);

            if (lwResult.Count != bible.Count)
            {
                Console.WriteLine("LightWeight DISQUALIFIED");
            }

            lwSerialize.Stop();

            Console.WriteLine("FORMAT      SIZE   SERIALIZE    DESERIALIZE");
            Console.WriteLine("JSON:      {0,5:N0}KB {1,5:N0}ms {2,5:N0}ms", nsOutput.Length / 1024, nsSerialize.ElapsedMilliseconds, nsDeserialize.ElapsedMilliseconds);
            Console.WriteLine("ProtoBuff: {0,5:N0}KB {1,5:N0}ms {2,5:N0}ms", pbOutput.Length / 1024, pbSerialize.ElapsedMilliseconds, pbDeserialize.ElapsedMilliseconds);
            Console.WriteLine("MsgPack:   {0,5:N0}KB {1,5:N0}ms {2,5:N0}ms", mpOutput.Length / 1024, mpSerialize.ElapsedMilliseconds, mpDeserialize.ElapsedMilliseconds);
            Console.WriteLine("LW:        {0,5:N0}KB {1,5:N0}ms {2,5:N0}ms", lwOutput.Length / 1024, lwSerialize.ElapsedMilliseconds, lwDeserialize.ElapsedMilliseconds);

            Console.WriteLine("Done.");
        }