Python Serialization Benchmark

This repository maintains a set of benchmarks for python serialization frameworks.

You can find the latest benchmarks on this page.

Currently the following projects are benchmarked.

Along with a baseline custom function that doesn't use a framework.

Running the test suite

A Docker container is bundled with the repository which you can use to run the benchmarks. Firstly make sure you have Docker installed.

  1. Install Docker

  2. Build the container $ docker-compose build

  3. Run the tests. $ docker-compose run --rm tests

Library                  Many Objects (seconds)    One Object (seconds)    Relative
---------------------  ------------------------  ----------------------  ----------
Custom                                0.0256822               0.013052      1
lima                                  0.0383852               0.0197146     1.49996
serpy                                 0.104605                0.0706699     4.52507
Strainer                              0.114318                0.0885544     5.23755
Toasted Marshmallow                   0.292227                0.135766     11.0495
Lollipop                              1.23894                 0.419955     42.8277
Marshmallow                           2.13818                 0.749287     74.5457
kim                                   2.46978                 1.32616      97.9997
Django REST Framework                 2.53841                 1.75292     110.789

The Benchmark

Each framework is asked to serialize a list of 2 objects a 1000 times, and then 1 object a 1000 times.

This is the current object that is being serialized.

class ChildTestObject(object):
    def __init__(self, multiplier=None):
        self.w = 1000 * multiplier if multiplier else 100
        self.x = 20 * multiplier if multiplier else 20
        self.y = 'hello' * multiplier if multiplier else 'hello'
        self.z = 10 * multiplier if multiplier else 10

class ParentTestObject(object):
    def __init__(self): = 'bar'
        self.sub = ChildTestObject()
        self.subs = [ChildTestObject(i) for i in xrange(10)]

    def bar(self):
        return 5

benchmark_object = ParentTestObject()


Serialization from python objects to JSON, XML, or other transmission formats is a common task for many web related projects. In order to fill that need a number of frameworks have arised. While their aims are similar, they don't all share the same attributes. Here are how some of the features comapre.

Project Serialization Encoding Deserialization Validation
Django REST Framework Yes Yes Yes Yes
serpy Yes No No No
marshmallow Yes Yes Yes Yes
Lollipop Yes No Yes Yes
strainer Yes Yes Yes Yes
kim Yes No Yes Yes