Exemplo n.º 1
0
    static T SerializeWire <T>(T original)
    {
        Console.WriteLine("Wire");

        T            copy   = default(T);
        MemoryStream stream = null;

        using (new Measure("Serialize"))
        {
            for (int i = 0; i < Iteration; i++)
            {
                wireSerializer.Serialize(original, stream = new MemoryStream());
            }
        }

        using (new Measure("Deserialize"))
        {
            for (int i = 0; i < Iteration; i++)
            {
                stream.Position = 0;
                copy            = wireSerializer.Deserialize <T>(stream);
            }
        }

        if (!dryRun)
        {
            Console.WriteLine(string.Format("{0,15}   {1}", "Binary Size", ToHumanReadableSize(stream.Position)));
        }

        return(copy);
    }
Exemplo n.º 2
0
    static T SerializeWire <T>(T original)
    {
        //  Console.WriteLine("Wire");

        T            copy   = default(T);
        MemoryStream stream = null;
        var          label  = "Wire." + original.GetType().Name;

        using (new Measure(label))
        {
            for (int i = 0; i < Iteration; i++)
            {
                wireSerializer.Serialize(original, stream = new MemoryStream());
            }
        }

        //using (new Measure("Deserialize"))
        //{
        //    for (int i = 0; i < Iteration; i++)
        //    {
        //        stream.Position = 0;
        //        copy = wireSerializer.Deserialize<T>(stream);
        //    }
        //}

        //if (!dryRun)
        //{
        //    Console.WriteLine(string.Format("{0,15}   {1}", "Binary Size", ToHumanReadableSize(stream.Position)));
        //}

        return(copy);
    }
Exemplo n.º 3
0
 public override byte[] ToBinary(object obj)
 {
     using (var ms = new MemoryStream())
     {
         _seralizer.Serialize(obj, ms);
         return(ms.ToArray());
     }
 }