public static void PerformanceTestArrayBuilderObject(Int32 arrayLength) { long before; before = Stopwatch.GetTimestamp(); for (int i = 0; i < 10000; i++) { ArrayBuilder builder = new ArrayBuilder(typeof(Object)); for (int j = 0; j < arrayLength; j++) { builder.Add(new Object()); } Array array = builder.Build(); } Console.WriteLine((Stopwatch.GetTimestamp() - before).StopwatchTicksAsInt64Milliseconds()); PrintGC("ArrayBuilder"); before = Stopwatch.GetTimestamp(); for (int i = 0; i < 10000; i++) { GenericArrayBuilder <Object> builder = new GenericArrayBuilder <Object>(); for (int j = 0; j < arrayLength; j++) { builder.Add(new Object()); } Array array = builder.Build(); } Console.WriteLine((Stopwatch.GetTimestamp() - before).StopwatchTicksAsInt64Milliseconds()); PrintGC("GenericArrayBuilder"); }
public override UInt32 Deserialize(Object instance, Byte[] array, UInt32 offset, UInt32 offsetLimit) { GenericArrayBuilder <ElementType> arrayBuilder = new GenericArrayBuilder <ElementType>(); while (true) { ElementType element; offset = elementSerializer.Deserialize(array, offset, offsetLimit, out element); arrayBuilder.Add(element); if (isLastElementCallback(element)) { fieldInfo.SetValue(instance, arrayBuilder.Build()); return(offset); } } }