static void Main(string[] args) { var sourceList = new Item[10000]; for (int i = 0; i < sourceList.Length; i++) { sourceList[i] = new Item { IntValue = i, StringValue = i.ToString() }; } var mySerializer = new YamlSerializer(); var myDeserializer = new YamlDeserializer(); var defaultSerializer = new Serializer(); var defaultDeserializer = new Deserializer(); var watch = new Stopwatch(); while (true) { var sw = new StringWriter(); watch.Restart(); mySerializer.Serialize(sw, sourceList); var stime = watch.ElapsedMilliseconds; watch.Restart(); var list = myDeserializer.Deserialize<List<Item>>(new StringReader(sw.ToString())); var dtime = watch.ElapsedMilliseconds; Console.WriteLine("My - Serialize time: {0}ms, Deserialize time: {1}ms", stime, dtime); sw = new StringWriter(); watch.Restart(); defaultSerializer.Serialize(sw, sourceList); stime = watch.ElapsedMilliseconds; watch.Restart(); list = defaultDeserializer.Deserialize<List<Item>>(new StringReader(sw.ToString())); dtime = watch.ElapsedMilliseconds; Console.WriteLine("Default - Serialize time: {0}ms, Deserialize time: {1}ms", stime, dtime); } }
public void Test_Basic_4() { var s = new YamlSerializer(); var sw = new StringWriter(); s.Serialize(sw, new Entity { IntValue = 1, StringValue = "1.23", BoolValue = true }); Assert.Equal(@"IntValue: 1 StringValue: ""1.23"" BoolValue: true ", sw.ToString()); var d = new YamlDeserializer(); var obj = d.Deserialize<Entity>(new StringReader(sw.ToString())); Assert.Equal(1, obj.IntValue); Assert.Equal("1.23", obj.StringValue); Assert.Equal(true, obj.BoolValue); var dict = d.Deserialize<Dictionary<string, object>>(new StringReader(sw.ToString())); Assert.Equal(1, dict["IntValue"]); Assert.Equal("1.23", dict["StringValue"]); Assert.Equal(true, dict["BoolValue"]); }