public void TestPerfomenceStrongTypeWithJsonNet() { IStrongStructure entity = new StrongStructure(); StrongTypeFormatter serializer = new StrongTypeFormatter(); var watch = Stopwatch.StartNew(); for (int i = 0; i < 1000; i++) { var buffer = serializer.Serialize(entity); serializer.Deserialize(buffer); } watch.Stop(); var jsonWatch = Stopwatch.StartNew(); for (int i = 0; i < 1000; i++) { var buffer = JsonConvert.SerializeObject(entity); var obj = JsonConvert.DeserializeObject(buffer); } jsonWatch.Stop(); var message = $"StrongTypeFormatter {watch.ElapsedMilliseconds} ms\r\nJsonConvert {jsonWatch.ElapsedMilliseconds} ms"; Assert.IsTrue(watch.ElapsedTicks < jsonWatch.ElapsedTicks, message); TestContext.WriteLine(message); }
public void StrongTypeFormatterPerformanceTest() { var strongTypeFormatter = new StrongTypeFormatter(); var testEntity = new ClassForTest(); var watch = Stopwatch.StartNew(); for (int i = 0; i < iterationCount; i++) { var buffer = strongTypeFormatter.Serialize(testEntity); var testEintity = strongTypeFormatter.Deserialize(buffer); } watch.Stop(); Debug.WriteLine($"StrongTypeFormatter result {watch.ElapsedMilliseconds} ms."); BinaryFormatter binary = new BinaryFormatter(); watch = Stopwatch.StartNew(); for (int i = 0; i < iterationCount; i++) { using (MemoryStream mStream = new MemoryStream()) { binary.Serialize(mStream, testEntity); mStream.Position = 0; var testEintity = binary.Deserialize(mStream); } } watch.Stop(); Debug.WriteLine($"BinarySerializer result {watch.ElapsedMilliseconds} ms."); }
public void TestPerfomenceStrongType() { IStrongStructure entity = new StrongStructure(); StrongTypeFormatter serializer = new StrongTypeFormatter(); var watch = Stopwatch.StartNew(); for (int i = 0; i < 1000; i++) { var buffer = serializer.Serialize(entity); serializer.Deserialize(buffer); } watch.Stop(); BinaryFormatter binary = new BinaryFormatter(); var binaryWatch = Stopwatch.StartNew(); for (int i = 0; i < 1000; i++) { using (MemoryStream mStream = new MemoryStream()) { binary.Serialize(mStream, entity); mStream.Position = 0; var obj = binary.Deserialize(mStream); } } binaryWatch.Stop(); var message = $"StrongTypeFormatter {watch.ElapsedMilliseconds} ms\r\nBinaryFormatter {binaryWatch.ElapsedMilliseconds} ms"; Assert.IsTrue(watch.ElapsedTicks < binaryWatch.ElapsedTicks, message); TestContext.WriteLine(message); }
public void StrongTypeFormatterNullableTest() { Nullable <bool> testEntity = true; var strongTypeFormatter = new StrongTypeFormatter(); var buffer = strongTypeFormatter.Serialize(testEntity); var resultEntity = strongTypeFormatter.Deserialize(buffer); Assert.AreEqual(testEntity, resultEntity); }
public void StrongTypeFormatterDateTimeTest() { var time = DateTime.Now; var strongTypeFormatter = new StrongTypeFormatter(); var buffer = strongTypeFormatter.Serialize(time); var resultTime = strongTypeFormatter.Deserialize(buffer); Assert.AreEqual(time, resultTime); }
public void StrongTypeFormatterStringTest() { var strongTypeFormatter = new StrongTypeFormatter(); var someString = "This is some string"; var stringBytes = strongTypeFormatter.Serialize(someString); var someStringCopy = strongTypeFormatter.Deserialize(stringBytes); Assert.AreEqual(someString, someStringCopy); }
public void StrongTypeFormatterStringInClass() { var strongTypeFormatter = new StrongTypeFormatter(); var testClass = new ClassWithStrings(); var classBytes = strongTypeFormatter.Serialize(testClass); var testClassCopy = (ClassWithStrings)strongTypeFormatter.Deserialize(classBytes); Assert.AreEqual(testClass.someString, testClassCopy.someString); Assert.AreEqual(testClass.secondSomeString, testClassCopy.secondSomeString); }
public void StrongTypeFormatterNullableWhenNullTest() { Nullable <bool> testEntity = null; try { var strongTypeFormatter = new StrongTypeFormatter(); var buffer = strongTypeFormatter.Serialize(testEntity); var resultEntity = strongTypeFormatter.Deserialize(buffer); Assert.Fail($"Serialize null value"); } catch { } }
public void StrongTypeFormatterNullableStructTest() { TestStruct?testEntity = new TestStruct() { B = 50, G = 10, R = 32 }; var strongTypeFormatter = new StrongTypeFormatter(); var buffer = strongTypeFormatter.Serialize(testEntity); var resultEntity = strongTypeFormatter.Deserialize(buffer); Assert.AreEqual(testEntity, resultEntity); }
public void StrongTypeFormatterClassTest() { var strongTypeFormatter = new StrongTypeFormatter(); var testEntity = new ClassForTest(); var watch = Stopwatch.StartNew(); for (int i = 0; i < iterationCount; i++) { var buffer = strongTypeFormatter.Serialize(testEntity); var testEintity = strongTypeFormatter.Deserialize(buffer); } watch.Stop(); Debug.WriteLine($"StrongTypeFormatter result {watch.ElapsedMilliseconds} ms."); }
public void StrongTypeFormatterStuctTest() { var strongTypeFormatter = new StrongTypeFormatter(); var testEntity = new TestStruct() { B = 50, G = 99, R = 1 }; var testEntityBytes = strongTypeFormatter.Serialize(testEntity); var testEintityResult = strongTypeFormatter.Deserialize(testEntityBytes); Assert.AreEqual(testEntity, testEintityResult); }
public void StrongTypeFormatterDateTimeInClass() { var firstDate = DateTime.Now; var secondDate = DateTime.Now.AddHours(1); var strongTypeFormatter = new StrongTypeFormatter(); var testEntity = new ClassWithDateTime() { FirstDate = firstDate, OtherDate = secondDate }; var buffer = strongTypeFormatter.Serialize(testEntity); var resultTime = (ClassWithDateTime)strongTypeFormatter.Deserialize(buffer); Assert.AreEqual(testEntity.FirstDate, resultTime.FirstDate); Assert.AreEqual(testEntity.OtherDate, resultTime.OtherDate); }