コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #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);
 }
コード例 #7
0
ファイル: Binary_FromStream.cs プロジェクト: tmat/performance
        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
        }
コード例 #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();
        }
コード例 #9
0
ファイル: Json_FromStream.cs プロジェクト: lewing/performance
        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);
        }
コード例 #10
0
ファイル: Json_FromStream.cs プロジェクト: lewing/performance
        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();
            }
        }
コード例 #11
0
ファイル: Json_FromStream.cs プロジェクト: lewing/performance
        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();
            }
        }
コード例 #12
0
 public void Setup() => value = DataGenerator.Generate <T>();
コード例 #13
0
ファイル: Json_FromString.cs プロジェクト: lewing/performance
 public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(DataGenerator.Generate <T>());
コード例 #14
0
ファイル: Json_FromString.cs プロジェクト: lewing/performance
 public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(DataGenerator.Generate <T>());
コード例 #15
0
ファイル: Json_FromString.cs プロジェクト: lewing/performance
 public void SetupJil() => serialized = Jil.JSON.Serialize <T>(DataGenerator.Generate <T>(), Jil.Options.ISO8601);