public Xml_FromStream() { value = DataGenerator.Generate <T>(); xmlSerializer = new XmlSerializer(typeof(T)); dataContractSerializer = new DataContractSerializer(typeof(T)); memoryStream = new MemoryStream(capacity: short.MaxValue); }
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); }
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); }
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); }
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); }
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); }
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 }
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(); }
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); }
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(); } }
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(); } }
public void Setup() => value = DataGenerator.Generate <T>();
public void SerializeUtf8Json_() => serialized = Utf8Json.JsonSerializer.ToJsonString(DataGenerator.Generate <T>());
public void SerializeJsonNet() => serialized = Newtonsoft.Json.JsonConvert.SerializeObject(DataGenerator.Generate <T>());
public void SetupJil() => serialized = Jil.JSON.Serialize <T>(DataGenerator.Generate <T>(), Jil.Options.ISO8601);