Skip to content

Latest commit

 

History

History
127 lines (116 loc) · 6.55 KB

File metadata and controls

127 lines (116 loc) · 6.55 KB

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):
        self.foo = 'bar'
        self.sub = ChildTestObject()
        self.subs = [ChildTestObject(i) for i in xrange(10)]

    def bar(self):
        return 5

benchmark_object = ParentTestObject()

Discussion

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 No Yes Yes
Kim Yes No Yes Yes
serpyco Yes Yes Yes Yes
Toasted Marshmallow Yes Yes Yes Yes
Colander Yes No Yes< Yes
Lima Yes No No No
Avro Yes Yes Yes No
  • Serialization: Does the framework provide a way of serializing python objects to simple datastructures
  • Encoding: Does the framework provide a way of encoding data into a wire format
  • Deserialization: Does the framework provide a way of deserializing simple data structures into complex data structures
  • Validation: Does the framework provide a way of validating datastructures, and reprorting error conditions
  • Part of Framework: Is serialization apart of a larger framework