Index: /trunk/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/UseCases.cs
===================================================================
--- /trunk/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/UseCases.cs	(revision 16593)
+++ /trunk/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/UseCases.cs	(revision 16594)
@@ -22,6 +22,8 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Drawing;
 using System.IO;
+using System.IO.Compression;
 using System.Linq;
 using System.Reflection;
@@ -35,4 +37,5 @@
 using HeuristicLab.Persistence.Core;
 using HeuristicLab.Persistence.Default.Xml;
+using HeuristicLab.Persistence.Interfaces;
 using HeuristicLab.Tests;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -151,4 +154,177 @@
       }
     }
+
+    [TestMethod]
+    [TestCategory("Persistence.Attic")]
+    [TestProperty("Time", "long")]
+    public void ProfileSamples() {
+      // CreateAllSamples();
+      var path = SamplesUtils.SamplesDirectory;
+      foreach (var fileName in Directory.EnumerateFiles(path, "*.hl")) {
+        //ProfilePersistenceToMemory(fileName);
+        ProfilePersistenceToDisk(fileName);
+      }
+    }
+
+    private void ProfilePersistenceToMemory(string fileName) {
+      var REPS = 5;
+      var oldDeserStopwatch = new Stopwatch();
+      var oldSerStopwatch = new Stopwatch();
+      var newDeserStopwatch = new Stopwatch();
+      var newSerStopwatch = new Stopwatch();
+      long oldSize = 0, newSize = 0;
+      var config = ConfigurationService.Instance.GetConfiguration(new XmlFormat());
+      int[] oldCollections = new int[3];
+      int[] newCollections = new int[3];
+
+      for (int i = 0; i < REPS; i++) {
+        var original = XmlParser.Deserialize(fileName);
+        object deserializedObject1 = null;
+        object deserializedObject2 = null;
+        byte[] buf;
+        System.GC.Collect();
+        var collection0 = System.GC.CollectionCount(0);
+        var collection1 = System.GC.CollectionCount(1);
+        var collection2 = System.GC.CollectionCount(2);
+        using (var s = new MemoryStream()) {
+
+          oldSerStopwatch.Start();
+          // serialize manually so that the stream won't be closed
+          var serializer = new Core.Serializer(original, config);
+          serializer.InterleaveTypeInformation = true;
+          using (StreamWriter writer = new StreamWriter(new GZipStream(s, CompressionMode.Compress))) {
+            XmlGenerator generator = new XmlGenerator();
+            foreach (ISerializationToken token in serializer) {
+              writer.Write(generator.Format(token));
+            }
+            writer.Flush();
+            oldSize += s.Length;
+          }
+
+          oldSerStopwatch.Stop();
+          buf = s.GetBuffer();
+        }
+        using (var s = new MemoryStream(buf)) {
+          oldDeserStopwatch.Start();
+          deserializedObject1 = XmlParser.Deserialize(s);
+          oldDeserStopwatch.Stop();
+        }
+
+        System.GC.Collect();
+        oldCollections[0] += System.GC.CollectionCount(0) - collection0;
+        oldCollections[1] += System.GC.CollectionCount(1) - collection1;
+        oldCollections[2] += System.GC.CollectionCount(2) - collection2;
+
+        collection0 = System.GC.CollectionCount(0);
+        collection1 = System.GC.CollectionCount(1);
+        collection2 = System.GC.CollectionCount(2);
+
+        // Protobuf only uses Deflate
+        using (var m = new MemoryStream()) {
+          //         using (var s = new GZipStream(m, CompressionMode.Compress)) { // same as old persistence
+          using (var s = new DeflateStream(m, CompressionMode.Compress)) { // new format
+            newSerStopwatch.Start();
+            (new ProtoBufSerializer()).Serialize(original, s, false);
+            s.Flush();
+            newSerStopwatch.Stop();
+            newSize += m.Length;
+          }
+          buf = m.GetBuffer();
+        }
+        using (var m = new MemoryStream(buf)) {
+          // using (var s = new GZipStream(m, CompressionMode.Decompress)) { // same as old persistence
+          using (var s = new DeflateStream(m, CompressionMode.Decompress)) { // new format
+            newDeserStopwatch.Start();
+            deserializedObject2 = (new ProtoBufSerializer()).Deserialize(s);
+            newDeserStopwatch.Stop();
+          }
+        }
+        //Assert.AreEqual(deserializedObject1.GetObjectGraphObjects().Count(), deserializedObject2.GetObjectGraphObjects().Count());
+
+        System.GC.Collect();
+        newCollections[0] += System.GC.CollectionCount(0) - collection0;
+        newCollections[1] += System.GC.CollectionCount(1) - collection1;
+        newCollections[2] += System.GC.CollectionCount(2) - collection2;
+      }
+
+      Console.WriteLine($"{fileName} " +
+        $"{oldSize / (double)REPS} " +
+        $"{newSize / (double)REPS} " +
+        $"{oldSerStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{newSerStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{oldDeserStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{newDeserStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{oldCollections[0] / (double)REPS} " +
+        $"{newCollections[0] / (double)REPS} " +
+        $"{oldCollections[1] / (double)REPS} " +
+        $"{newCollections[1] / (double)REPS} " +
+        $"{oldCollections[2] / (double)REPS} " +
+        $"{newCollections[2] / (double)REPS} " +
+        $"");
+    }
+
+    private void ProfilePersistenceToDisk(string fileName) {
+      var REPS = 5;
+      var oldDeserStopwatch = new Stopwatch();
+      var oldSerStopwatch = new Stopwatch();
+      var newDeserStopwatch = new Stopwatch();
+      var newSerStopwatch = new Stopwatch();
+      long oldSize = 0, newSize = 0;
+      int[] oldCollections = new int[3];
+      int[] newCollections = new int[3];
+
+      for (int i = 0; i < REPS; i++) {
+        var original = XmlParser.Deserialize(fileName);
+        byte[] buf;
+        System.GC.Collect();
+        var collection0 = System.GC.CollectionCount(0);
+        var collection1 = System.GC.CollectionCount(1);
+        var collection2 = System.GC.CollectionCount(2);
+
+        oldSerStopwatch.Start();
+        XmlGenerator.Serialize(original, tempFile);
+        oldSerStopwatch.Stop();
+
+        oldSize += new FileInfo(tempFile).Length;
+        oldDeserStopwatch.Start();
+        var clone = XmlParser.Deserialize(tempFile);
+        oldDeserStopwatch.Stop();
+        System.GC.Collect();
+        oldCollections[0] += System.GC.CollectionCount(0) - collection0;
+        oldCollections[1] += System.GC.CollectionCount(1) - collection1;
+        oldCollections[2] += System.GC.CollectionCount(2) - collection2;
+
+        collection0 = System.GC.CollectionCount(0);
+        collection1 = System.GC.CollectionCount(1);
+        collection2 = System.GC.CollectionCount(2);
+
+        newSerStopwatch.Start();
+        (new ProtoBufSerializer()).Serialize(original, tempFile);
+        newSerStopwatch.Stop();
+        newSize += new FileInfo(tempFile).Length;
+        newDeserStopwatch.Start();
+        var newClone = (new ProtoBufSerializer()).Deserialize(tempFile);
+        newDeserStopwatch.Stop();
+        System.GC.Collect();
+        newCollections[0] += System.GC.CollectionCount(0) - collection0;
+        newCollections[1] += System.GC.CollectionCount(1) - collection1;
+        newCollections[2] += System.GC.CollectionCount(2) - collection2;
+      }
+      Console.WriteLine($"{fileName} " +
+        $"{oldSize / (double)REPS} " +
+        $"{newSize / (double)REPS} " +
+        $"{oldSerStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{newSerStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{oldDeserStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{newDeserStopwatch.ElapsedMilliseconds / (double)REPS} " +
+        $"{oldCollections[0] / (double)REPS} " +
+        $"{newCollections[0] / (double)REPS} " +
+        $"{oldCollections[1] / (double)REPS} " +
+        $"{newCollections[1] / (double)REPS} " +
+        $"{oldCollections[2] / (double)REPS} " +
+        $"{newCollections[2] / (double)REPS} " +
+        $"");
+    }
+
 
     [TestMethod]
