Ejemplo n.º 1
0
 public Xml_FromStream()
 {
     value                  = DataGenerator.Generate <T>();
     xmlSerializer          = new XmlSerializer(typeof(T));
     dataContractSerializer = new DataContractSerializer(typeof(T));
     memoryStream           = new MemoryStream(capacity: short.MaxValue);
 }
Ejemplo n.º 2
0
 public void SetupDataContractSerializer()
 {
     value                  = DataGenerator.Generate <T>();
     memoryStream           = new MemoryStream(capacity: short.MaxValue);
     memoryStream.Position  = 0;
     dataContractSerializer = new DataContractSerializer(typeof(T));
     dataContractSerializer.WriteObject(memoryStream, value);
 }
Ejemplo n.º 3
0
 public void SetupXmlSerializer()
 {
     value                 = DataGenerator.Generate <T>();
     memoryStream          = new MemoryStream(capacity: short.MaxValue);
     memoryStream.Position = 0;
     xmlSerializer         = new XmlSerializer(typeof(T));
     xmlSerializer.Serialize(memoryStream, value);
 }
Ejemplo n.º 4
0
 public void SetupMessagePack()
 {
     value = DataGenerator.Generate <T>();
     // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
     memoryStream          = new MemoryStream(capacity: short.MaxValue);
     memoryStream.Position = 0;
     MessagePack.MessagePackSerializer.Serialize <T>(memoryStream, value);
 }
Ejemplo n.º 5
0
 public void SetupBinaryFormatter()
 {
     value = DataGenerator.Generate <T>();
     // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
     memoryStream          = new MemoryStream(capacity: short.MaxValue);
     memoryStream.Position = 0;
     binaryFormatter       = new BinaryFormatter();
     binaryFormatter.Serialize(memoryStream, value);
 }
Ejemplo n.º 6
0
 public void SetupProtoBuffNet()
 {
     value = DataGenerator.Generate <T>();
     // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
     memoryStream          = new MemoryStream(capacity: short.MaxValue);
     memoryStream.Position = 0;
     ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(DateTimeOffset), false).SetSurrogate(typeof(DateTimeOffsetSurrogate)); // https://stackoverflow.com/a/7046868
     ProtoBuf.Serializer.Serialize(memoryStream, value);
 }
Ejemplo n.º 7
0
        public Binary_FromStream()
        {
            value = DataGenerator.Generate <T>();

            // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
            memoryStream    = new MemoryStream(capacity: short.MaxValue);
            binaryFormatter = new BinaryFormatter();

            ProtoBuf.Meta.RuntimeTypeModel.Default.Add(typeof(DateTimeOffset), false).SetSurrogate(typeof(DateTimeOffsetSurrogate)); // https://stackoverflow.com/a/7046868
        }
Ejemplo n.º 8
0
        public Json_FromStream()
        {
            value = DataGenerator.Generate <T>();

            // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
            memoryStream = new MemoryStream(capacity: short.MaxValue);

            dataContractJsonSerializer = new DataContractJsonSerializer(typeof(T));
            newtonSoftJsonSerializer   = new Newtonsoft.Json.JsonSerializer();
        }
Ejemplo n.º 9
0
        public void SetupDataContractJsonSerializer_()
        {
            value = DataGenerator.Generate <T>();

            // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
            memoryStream               = new MemoryStream(capacity: short.MaxValue);
            memoryStream.Position      = 0;
            dataContractJsonSerializer = new DataContractJsonSerializer(typeof(T));
            dataContractJsonSerializer.WriteObject(memoryStream, value);
        }
Ejemplo n.º 10
0
        public void SetupJil_()
        {
            value = DataGenerator.Generate <T>();

            // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
            memoryStream          = new MemoryStream(capacity: short.MaxValue);
            memoryStream.Position = 0;

            using (var writer = new StreamWriter(memoryStream, Encoding.UTF8, short.MaxValue, leaveOpen: true))
            {
                Jil.JSON.Serialize <T>(value, writer, Jil.Options.ISO8601);
                writer.Flush();
            }
        }
Ejemplo n.º 11
0
        public void SetupJsonNet_()
        {
            value = DataGenerator.Generate <T>();

            // the stream is pre-allocated, we don't want the benchmarks to include stream allocaton cost
            memoryStream          = new MemoryStream(capacity: short.MaxValue);
            memoryStream.Position = 0;

            newtonSoftJsonSerializer = new Newtonsoft.Json.JsonSerializer();

            using (var writer = new StreamWriter(memoryStream, Encoding.UTF8, short.MaxValue, leaveOpen: true))
            {
                newtonSoftJsonSerializer.Serialize(writer, value);
                writer.Flush();
            }
        }
Ejemplo n.º 12
0
 public void Setup() => value = DataGenerator.Generate <T>();
Ejemplo n.º 13
0
 public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(DataGenerator.Generate <T>());
Ejemplo n.º 14
0
 public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(DataGenerator.Generate <T>());
Ejemplo n.º 15
0
 public void SetupJil() => serialized = Jil.JSON.Serialize <T>(DataGenerator.Generate <T>(), Jil.Options.ISO8601);