Index: branches/PersistenceOverhaul/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs
===================================================================
--- branches/PersistenceOverhaul/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs	(revision 13408)
+++ branches/PersistenceOverhaul/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs	(revision 13409)
@@ -23,4 +23,5 @@
 using System.Collections;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Drawing;
 using System.Globalization;
@@ -31,4 +32,5 @@
 using System.Threading.Tasks;
 using HeuristicLab.Algorithms.GeneticAlgorithm;
+using HeuristicLab.Data;
 using HeuristicLab.Persistence;
 using HeuristicLab.Persistence.Auxiliary;
@@ -42,4 +44,11 @@
 
 namespace HeuristicLab.PersistenceNew.Tests {
+  public static class EnumerableTimeSpanExtensions {
+    public static TimeSpan Average(this IEnumerable<TimeSpan> span) {
+      var avg = (long)Math.Round(span.Select(x => x.Ticks).Average());
+      return new TimeSpan(avg);
+    }
+  }
+
   #region Test Classes
   [StorableClass("7D9672BD-703D-42BB-9080-9929885D4580")]
@@ -264,4 +273,9 @@
   }
 
+  public class SimpleClass {
+    public double x { get; set; }
+    public int y { get; set; }
+  }
+
   #endregion
 
@@ -290,66 +304,504 @@
     #endregion
 
+    #region Persistence 4.0 Profiling Helpers  
+    public class PerformanceData {
+      public TimeSpan OldSerializingTime { get; set; }
+      public TimeSpan NewSerializingTime { get; set; }
+      public TimeSpan OldDeserializingTime { get; set; }
+      public TimeSpan NewDeserializingTime { get; set; }
+      public long OldFileSize { get; set; }
+      public long NewFileSize { get; set; }
+      public long OldSerializingMemoryConsumed { get; set; }
+      public long NewSerializingMemoryConsumed { get; set; }
+      public long OldDeserializingMemoryConsumed { get; set; }
+      public long NewDeserializingMemoryConsumed { get; set; }
+    }
+
+    private void SerializeNew(object o) {
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(o, tempFile);
+    }
+    private void SerializeOld(object o) {
+      XmlGenerator.Serialize(o, tempFile);
+    }
+    private object DeserializeNew() {
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      return serializer.Deserialize(tempFile);
+    }
+    private object DeserialiezOld() {
+      return XmlParser.Deserialize(tempFile);
+    }
+
+    private void CollectGarbage() {
+      GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
+      GC.WaitForPendingFinalizers();
+    }
+
+    public PerformanceData ProfileSingleRun(Func<object> GenerateDataFunc) {
+      PerformanceData performanceData = new PerformanceData();
+      Stopwatch sw = new Stopwatch();
+      object data = GenerateDataFunc();
+      object result = null;
+      long startMem, endMem;
+
+
+      //old file format serializing
+      CollectGarbage();
+      startMem = GC.GetTotalMemory(false);
+      sw.Start();
+      SerializeOld(data);
+      sw.Stop();
+      endMem = GC.GetTotalMemory(false);
+      performanceData.OldSerializingTime = sw.Elapsed;
+      performanceData.OldFileSize = new FileInfo(tempFile).Length;
+      performanceData.OldSerializingMemoryConsumed = endMem - startMem;
+      sw.Reset();
+
+
+      //old file format deserializing
+      CollectGarbage();
+      startMem = GC.GetTotalMemory(false);
+      sw.Start();
+      result = DeserialiezOld();
+      sw.Stop();
+      endMem = GC.GetTotalMemory(false);
+      performanceData.OldDeserializingTime = sw.Elapsed;
+      performanceData.OldDeserializingMemoryConsumed = endMem - startMem;
+      sw.Reset();
+
+
+      //new file format serializing
+      CollectGarbage();
+      startMem = GC.GetTotalMemory(false);
+      sw.Start();
+      SerializeNew(data);
+      sw.Stop();
+      endMem = GC.GetTotalMemory(false);
+      performanceData.NewSerializingTime = sw.Elapsed;
+      performanceData.NewSerializingMemoryConsumed = endMem - startMem;
+      performanceData.NewFileSize = new FileInfo(tempFile).Length;
+      sw.Reset();
+
+
+      //new file format deserializing
+      CollectGarbage();
+      startMem = GC.GetTotalMemory(false);
+      sw.Start();
+      result = DeserializeNew();
+      sw.Stop();
+      endMem = GC.GetTotalMemory(false);
+      performanceData.NewDeserializingTime = sw.Elapsed;
+      performanceData.NewDeserializingMemoryConsumed = endMem - startMem;
+      sw.Reset();
+
+      return performanceData;
+    }
+
+    public string Profile(Func<object> GenerateDataFunc) {
+      int nrOfRepetitions = 10;
+      StringBuilder report = new StringBuilder();
+      List<PerformanceData> dataList = new List<PerformanceData>();
+
+      for (int i = 0; i < nrOfRepetitions; i++) {
+        dataList.Add(ProfileSingleRun(GenerateDataFunc));
+      }
+
+      report.Append("Performance Report for " + GenerateDataFunc.Method.Name + ": " + Environment.NewLine);
+      report.Append(Environment.NewLine);
+      report.AppendFormat("Avg. old vs. new time for serializing a file: {0} / {1}; Factor: {2}",
+              dataList.Select(x => x.OldSerializingTime).Average(),
+              dataList.Select(x => x.NewSerializingTime).Average(),
+              dataList.Select(x => x.OldSerializingTime.TotalMilliseconds).Average() / dataList.Select(x => x.NewSerializingTime.TotalMilliseconds).Average()
+              );
+      report.Append(Environment.NewLine);
+      report.AppendFormat("Avg. old vs. new time for deserializing a file: {0} / {1}; Factor: {2}",
+              dataList.Select(x => x.OldDeserializingTime).Average(),
+              dataList.Select(x => x.NewDeserializingTime).Average(),
+              dataList.Select(x => x.OldDeserializingTime.TotalMilliseconds).Average() / dataList.Select(x => x.NewDeserializingTime.TotalMilliseconds).Average()
+              );
+      report.Append(Environment.NewLine);
+      report.AppendFormat("Avg. old vs. new file size (in bytes): {0} / {1}; Factor: {2}",
+              dataList.Select(x => x.OldFileSize).Average(),
+              dataList.Select(x => x.NewFileSize).Average(),
+              dataList.Select(x => x.OldFileSize).Average() / dataList.Select(x => x.NewFileSize).Average()
+              );
+      report.Append(Environment.NewLine);
+      report.AppendFormat("Avg. old vs. new memory consumption for serializing a file (in bytes): {0} / {1}; Factor: {2}",
+              dataList.Select(x => x.OldSerializingMemoryConsumed).Average(),
+              dataList.Select(x => x.NewSerializingMemoryConsumed).Average(),
+              dataList.Select(x => x.OldSerializingMemoryConsumed).Average() / dataList.Select(x => x.NewSerializingMemoryConsumed).Average()
+              );
+      report.Append(Environment.NewLine);
+      report.AppendFormat("Avg. old vs. new memory consumption for deserializing a file (in bytes): {0} / {1}; Factor: {2}",
+              dataList.Select(x => x.OldDeserializingMemoryConsumed).Average(),
+              dataList.Select(x => x.NewDeserializingMemoryConsumed).Average(),
+              dataList.Select(x => x.OldDeserializingMemoryConsumed).Average() / dataList.Select(x => x.NewDeserializingMemoryConsumed).Average()
+              );
+      report.Append(Environment.NewLine);
+
+
+      return report.ToString();
+    }
+    #endregion
+
     #region Persistence 4.0 test methods
     [TestMethod]
-    [TestCategory("Persistence")]
+    [TestCategory("Persistence4")]
     [TestProperty("Time", "short")]
     public void TestBool() {
-      bool test = true;
-      ProtoBufSerializer serializer = new ProtoBufSerializer();
-      serializer.Serialize(test, tempFile);
+      var test = new Func<object>(() => { return true; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
       object o = serializer.Deserialize(tempFile);
       bool result = (bool)o;
-      Assert.AreEqual(test, result);
-    }
-
-    [TestMethod]
-    [TestCategory("Persistence")]
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
     [TestProperty("Time", "short")]
     public void TestInt() {
-      int test = 42;
-      ProtoBufSerializer serializer = new ProtoBufSerializer();
-      serializer.Serialize(test, tempFile);
+      var test = new Func<object>(() => { return (int)42; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
       object o = serializer.Deserialize(tempFile);
       int result = (int)o;
-      Assert.AreEqual(test, result);
-    }
-
-    [TestMethod]
-    [TestCategory("Persistence")]
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestDouble() {
+      var test = new Func<object>(() => { return 42.5d; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      double result = (double)o;
+      Assert.AreEqual(test(), result);
+      Assert.IsTrue(o is double);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestFloat() {
+      var test = new Func<object>(() => { return 42.5f; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      float result = (float)o;
+      Assert.AreEqual(test(), result);
+      Assert.IsTrue(o is float);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestDecimal() {
+      var test = new Func<object>(() => { return 42.5m; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      decimal result = (decimal)o;
+      Assert.AreEqual(test(), result);
+      Assert.IsTrue(o is decimal);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestLong() {
+      var test = new Func<object>(() => { return 42l; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      long result = (long)o;
+      Assert.AreEqual(test(), result);
+      Assert.IsTrue(o is long);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestUInt() {
+      var test = new Func<object>(() => { return 42u; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      uint result = (uint)o;
+      Assert.AreEqual(test(), result);
+      Assert.IsTrue(o is uint);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestShort() {
+      var test = new Func<object>(() => { short s = 42; return s; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      short result = (short)o;
+      Assert.IsTrue(o is short);
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestByte() {
+      var test = new Func<object>(() => { byte b = 42; return b; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      byte result = (byte)o;
+      Assert.IsTrue(o is byte);
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
     [TestProperty("Time", "short")]
     public void TestEnumSimple() {
-      SimpleEnum se = SimpleEnum.two;
-      ComplexEnum ce = ComplexEnum.three;
-      ProtoBufSerializer serializer = new ProtoBufSerializer();
-      serializer.Serialize(se, tempFile);
+      var test = new Func<object>(() => { return SimpleEnum.two; });
+
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
       object o = serializer.Deserialize(tempFile);
       SimpleEnum result = (SimpleEnum)o;
-      Assert.AreEqual(se, result);
-    }
-
-    [TestMethod]
-    [TestCategory("Persistence")]
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
     [TestProperty("Time", "short")]
     public void TestEnumComplex() {
-      ComplexEnum ce = ComplexEnum.three;
-      ProtoBufSerializer serializer = new ProtoBufSerializer();
-      serializer.Serialize(ce, tempFile);
+      var test = new Func<object>(() => { return ComplexEnum.three; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
       object o = serializer.Deserialize(tempFile);
       ComplexEnum result = (ComplexEnum)o;
-      Assert.AreEqual(ce, result);
-    }
-
-    [TestMethod]
-    [TestCategory("Persistence")]
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
     [TestProperty("Time", "short")]
     public void TestType() {
-      Type test = typeof(HeuristicLab.Algorithms.GeneticAlgorithm.GeneticAlgorithm);
-      ProtoBufSerializer serializer = new ProtoBufSerializer();
-      serializer.Serialize(test, tempFile);
+      var test = new Func<object>(() => { return typeof(HeuristicLab.Algorithms.GeneticAlgorithm.GeneticAlgorithm); });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
       object o = serializer.Deserialize(tempFile);
       Type result = (Type)o;
-      Assert.AreEqual(test, result);
-    }
-
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestBytes() {
+      var test = new Func<byte[]>(() => { return new byte[] { 3, 1 }; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      byte[] result = (byte[])o;
+      Assert.AreEqual(test()[0], result[0]);
+      Assert.AreEqual(test()[1], result[1]);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestString() {
+      var test = new Func<object>(() => { return "Hello World!"; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      string result = (string)o;
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestColor() {
+      var test = new Func<object>(() => { return Color.DeepSkyBlue; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      Color result = (Color)o;
+      Assert.AreEqual(test(), result);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestPoint() {
+      var test = new Func<object>(() => { return new Point(3, 4); });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      Point result = (Point)o;
+      Assert.AreEqual(((Point)test()).X, result.X);
+      Assert.AreEqual(((Point)test()).Y, result.Y);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestBoolArray() {
+      var test = new Func<bool[]>(() => { return new[] { true, false, true }; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      bool[] result = (bool[])o;
+      Assert.AreEqual(test()[0], result[0]);
+      Assert.AreEqual(test()[1], result[1]);
+      Assert.AreEqual(test()[2], result[2]);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestIntArray() {
+      var test = new Func<int[]>(() => { return new[] { 41, 22, 13 }; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      int[] result = (int[])o;
+      Assert.AreEqual(test()[0], result[0]);
+      Assert.AreEqual(test()[1], result[1]);
+      Assert.AreEqual(test()[2], result[2]);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestLongArray() {
+      var test = new Func<long[]>(() => { return new[] { 414481188112191633l, 245488586662l, 13546881335845865l }; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      long[] result = (long[])o;
+      Assert.AreEqual(test()[0], result[0]);
+      Assert.AreEqual(test()[1], result[1]);
+      Assert.AreEqual(test()[2], result[2]);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestDoubleArray() {
+      var test = new Func<double[]>(() => { return new[] { 41.5, 22.7, 13.8 }; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      double[] result = (double[])o;
+      Assert.AreEqual(test()[0], result[0]);
+      Assert.AreEqual(test()[1], result[1]);
+      Assert.AreEqual(test()[2], result[2]);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestObjectArray() {
+      var test = new Func<SimpleClass[]>(() => {
+        return new[] { new SimpleClass() { x = 42, y = 43 },
+                       new SimpleClass() { x = 44.44, y = 5677 },
+                       new SimpleClass() { x = 533.33, y = 2345 } };
+      });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      SimpleClass[] result = (SimpleClass[])o;
+      Assert.AreEqual(test()[0].x, result[0].x);
+      Assert.AreEqual(test()[0].y, result[0].y);
+      Assert.AreEqual(test()[1].x, result[1].x);
+      Assert.AreEqual(test()[1].y, result[1].y);
+      Assert.AreEqual(test()[2].x, result[2].x);
+      Assert.AreEqual(test()[2].y, result[2].y);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
+
+    [TestMethod]
+    [TestCategory("Persistence4")]
+    [TestProperty("Time", "short")]
+    public void TestIntValueArray() {
+      var test = new Func<IntValue[]>(() => { return new[] { new IntValue(41), new IntValue(22), new IntValue(13) }; });
+      ProtoBufSerializer serializer = new ProtoBufSerializer();
+      serializer.Serialize(test(), tempFile);
+      object o = serializer.Deserialize(tempFile);
+      IntValue[] result = (IntValue[])o;
+      Assert.AreEqual(test()[0], result[0]);
+      Assert.AreEqual(test()[1], result[1]);
+      Assert.AreEqual(test()[2], result[2]);
+
+      string msg = Profile(test);
+      Console.WriteLine(msg);
+    }
     #endregion
 
