Exemple #1
0
        private static void Binary()
        {
            GC.Collect();

            Console.WriteLine("Binary");

            var ser = new ExpressionSerializer(new BinaryObjectSerializer(), ExpressionFactory.Instance);

            var N = 10000;
            var M = 10000;

            var e = (Expression <Func <IEnumerable <int> > >)(() => Enumerable.Range(0, 10).Where(x => x > 0).Select(x => x * x));

            Console.WriteLine("  Serialize");

            var sw = Stopwatch.StartNew();
            var gc = GarbageCollectionWatch.StartNew();

            var res = default(byte[]);

            for (var i = 0; i < N; i++)
            {
#if USE_SLIM
                res = ser.Serialize(e.ToExpressionSlim());
#else
                res = ser.Serialize(e);
#endif
            }

            Console.WriteLine("    Elapsed (ms): " + sw.Elapsed.TotalMilliseconds / M);
            Console.WriteLine("    " + gc.Elapsed);
            Console.WriteLine("    Length (bytes): " + res.Length);

            Console.WriteLine("  Deserialize");

            sw.Restart();
            gc.Restart();

            for (var i = 0; i < M; i++)
            {
#if USE_SLIM
                e = (Expression <Func <IEnumerable <int> > >)ser.Deserialize(res).ToExpression();
#else
                e = (Expression <Func <IEnumerable <int> > >)ser.Deserialize(res);
#endif
            }

            Console.WriteLine("    Elapsed (ms): " + sw.Elapsed.TotalMilliseconds / M);
            Console.WriteLine("    " + gc.Elapsed);

            Console.WriteLine();
        }
Exemple #2
0
        private static void Json()
        {
            GC.Collect();

            Console.WriteLine("JSON");

            var ser = new CustomBonsaiSerializer();

            var N = 10000;
            var M = 10000;

            var e = (Expression <Func <IEnumerable <int> > >)(() => Enumerable.Range(0, 10).Where(x => x > 0).Select(x => x * x));

            Console.WriteLine("  Serialize");

            var sw = Stopwatch.StartNew();
            var gc = GarbageCollectionWatch.StartNew();

            var res = default(string);

            for (var i = 0; i < N; i++)
            {
                res = ser.Serialize(e.ToExpressionSlim());
            }

            Console.WriteLine("    Elapsed (ms): " + sw.Elapsed.TotalMilliseconds / M);
            Console.WriteLine("    " + gc.Elapsed);
            Console.WriteLine("    Length (bytes): " + res.Length * 2);

            Console.WriteLine("  Deserialize");

            sw.Restart();
            gc.Restart();

            for (var i = 0; i < M; i++)
            {
                e = (Expression <Func <IEnumerable <int> > >)ser.Deserialize(res).ToExpression();
            }

            Console.WriteLine("    Elapsed (ms): " + sw.Elapsed.TotalMilliseconds / M);
            Console.WriteLine("    " + gc.Elapsed);

            Console.WriteLine();
        }