static void CompareValuesAndLogResults(Person person, Person newPerson, PerformanceLog perfLog, Type streamType, PerformanceLogEntryType type) { perfLog.LogData(String.Format("newPersonFrom{0}.Name and person.Name are equal", streamType.Name), String.Equals(newPerson.Name, person.Name), type); perfLog.LogData(String.Format("newPersonFrom{0}.ID and person.ID are equal", streamType.Name), int.Equals(newPerson.ID, person.ID), type); perfLog.LogData(String.Format("newPersonFrom{0}.Email and person.Email are equal", streamType.Name), String.Equals(newPerson.Email, person.Email), type); PhoneNumber[] phone = person.Phone.ToArray(); PhoneNumber[] newPhone = newPerson.Phone.ToArray(); for (int i = 0; i < phone.Length; i++) { perfLog.LogData(String.Format("PhoneNumber[{0}].Number from newPersonFrom{1}.Phone is the same as PhoneNumber[{0}].Number from person{1}.Phone", i, streamType.Name), phone[i].Number.Equals(newPhone[i].Number), type); perfLog.LogData(String.Format("PhoneNumber[{0}].Type from newPersonFrom{1}.Phone is the same as PhoneNumber[{0}].Type from person{1}.Phone", i, streamType.Name), phone[i].Type.Equals(newPhone[i].Type), type); } }
public PerformanceLog RunSerializationTest(long sequenceID, SerializerPerformanceTestAgent agent) { Stopwatch timer = new Stopwatch(); Stopwatch.UnitPrecision = UnitPrecision.NANOSECONDS; PerformanceLog perfLog = new PerformanceLog { Entries = new List <Entry>(), UnitPrecision = Stopwatch.UnitPrecision }; if (totalCount == 0) { startTime = DateTime.Now; UpdateUI(() => jsUpdateElement.InvokeSelf("startTime", startTime)); } Person person = null; Uri uri = new Uri(String.Format("http://localhost:9999/Person_{0}.xml", sequenceID), UriKind.Absolute); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri); int id = (int)sequenceID; using (timer) { timer.Scope = () => { timer.LogScope("Create a Person object", perfLog, PerformanceLogEntryType.CompiledObjectCreation, () => { person = CreatePerson(sequenceID); }); Stream serializedMemoryStream = null; timer.LogScope("Serialize the Person object to a MemoryStream", perfLog, PerformanceLogEntryType.Serialization, () => { serializedMemoryStream = SerializeToStream <Person>(person, null, agent.ISerializerTestAgent); }).LogData("Length (in bytes) of memoryStream", serializedMemoryStream.Length, PerformanceLogEntryType.StreamSize); timer.LogScope("Send the serialized MemoryStream to S3", perfLog, PerformanceLogEntryType.SendSerializedObjectTime, () => { //client.OpenWriteAsync(uri); }); timer.LogScope("Request the serialized object back from S3", perfLog, PerformanceLogEntryType.ReceiveSerializedObjectTime, () => { request.BeginGetResponse(new AsyncCallback(ReadCallback), request); }); Person newPersonFromMemoryStream = null; using (serializedMemoryStream) { timer.LogScope("Deserialize and parse the Person object from a MemoryStream", perfLog, PerformanceLogEntryType.Deserialization, () => { newPersonFromMemoryStream = DeserializeFromStream <Person>(serializedMemoryStream, agent.ISerializerTestAgent); }); } CompareValuesAndLogResults(person, newPersonFromMemoryStream, perfLog, typeof(MemoryStream), PerformanceLogEntryType.DeserializationCorrect); }; perfLog.LogData("Duration of test", timer.Duration, PerformanceLogEntryType.TotalDuration); } return(perfLog); }