Windows Phone 8 Serialization: Comparison

3 minute read

Two years ago I have made a serialization comparison for serializers Windows Phone 7 platform and that time Binary Serialization was an absolute winner. Now it is time to compare the results for Binary Serialization, DataContract serialization, DataContract JSON serialization and XML serialization again, but this time for Windows Phone 8 platform. The source code for this comparison is located within my WPPerfLab project at GitHub. All executed tests are using an instance of ProductEntity class for serialization and deserialization. This class contains few string properties and a list of strings(Keys property) with 10000 items inside. I have created a helper class for each of serializers which implements a basic ISerializationHelper interface.

public interface ISerializationHelper
    void Serialize(Stream streamObject, object objectForSerialization);
    object Deserialize(Stream streamObject, Type serializedObjectType);

Binary serialization

First of all, there is no out of the box support for binary serialization. I had to create my own binary serializer which internally uses BinaryWriter and BinaryReader to write and read binary data from and to a stream. Currently my SimpleBinarySerializer supports only strings and IList types, but eventually I might add a support for other types including generic ones. I am not going paste the source code for my binary serializer here, but you can check it at GitHub instead. Bellow is the source code for BinarySerializationHelper, which acts as a wrapper on top of SimpleBinarySerializer.

public class BinarySerializationHelper : ISerializationHelper
    public void Serialize(Stream streamObject, object objectForSerialization)
        if (objectForSerialization == null || streamObject == null)

        var ser = new SimpleBinarySerializer(objectForSerialization.GetType());
        ser.WriteObject(streamObject, objectForSerialization);

    public object Deserialize(Stream streamObject, Type serializedObjectType)
        if (serializedObjectType == null || streamObject == null)
            return null;

        var ser = new SimpleBinarySerializer(serializedObjectType);
        return ser.ReadObject(streamObject);

Executing tests

All tests were executed on a Lumia 920 Windows Phone 8 device(Portico). Each of the tests for a particular serialization method is executed 10 times and I have used the StopWatch to fetch the elapsed execution time for both serialization and deserialization processes. During the execution I have also measured the stream size in bytes. Bellow is the code I have used for a single test.

private List<Tuple<long, double, double>> ExecuteSerializationTests(
    ISerializationHelper serializationHelper,
    ProductEntity product,
    int numberOfTimes)
    var allResults = new List<Tuple<long, double, double>>();
    for (int i = 0; i < numberOfTimes; i++)
        using (var memoryStream = new MemoryStream())
            // serialization
            serializationHelper.Serialize(memoryStream, product);
            var serializationTime = sw.ElapsedMilliseconds;

            // get size in bytes
            var size = memoryStream.Length;

            // reset position of stream
            memoryStream.Position = 0;

            // deserialization
            var o = serializationHelper.Deserialize(memoryStream, typeof(ProductEntity));
            var deserializationTime = sw.ElapsedMilliseconds;

            allResults.Add(new Tuple<long, double, double>(size, serializationTime, deserializationTime));

            // close stream instead of relying on "using"
    return allResults;


Here are the results containing stream size in bytes, average serialization and deserialization time in milliseconds. Based on the table bellow I can say that Binary serialization is a clear winner again in all categories: stream size, serialization and deserialization time. DataContractJSON has a second place in stream size, but the elapsed time for deserialization is very disappointing. At the same time, DataContract takes roughly the same time for serialization and deserialization as XML serialization, also considering the fact that both serializers produce quite a huge stream, around 300KB.

Serialization type Stream size(bytes) Serialization time(ms) Deserialization time(ms)
Binary 79188 11.4 8.1
DataContract 339486 35.0 48.0
DataContractJSON 99236 52.7 146.0
XML Serialization 299453 24.4 53.7


If you don’t aim for consuming stream or file produced by serialization on other platforms, please, consider implementing binary serializer. The time it takes to serialize and deserialize an object using binary serializer is astonishing, but, unfortunately, the produced file is not readable by other services and it might take you some time to implement even a basic binary serializer for your application. If the produced stream or file will be used by other systems or services you can pick any other serializer based on the results above. If you are planning to have a smaller stream/file size, but at the same time in a more cross-platform format, aim for DataContractJSON serializer, but keep in mind that deserialization might take more time for any other serializer.