<commit_before>"""
Prints a comparison between different serializers.
Compares results based on size of the output, and time taken to (de)serialize.
"""

from __future__ import print_function
from timeit import default_timer as perf_timer
import sys

class Person(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age


data = {

    "bytes": b"0123456789abcdefghijklmnopqrstuvwxyz" * 2000,
    "bytearray": bytearray(b"0123456789abcdefghijklmnopqrstuvwxyz") * 2000,
    "str": "\"0123456789\"\n'abcdefghijklmnopqrstuvwxyz'\t" * 2000,
    "unicode": u"abcdefghijklmnopqrstuvwxyz\u20ac\u20ac\u20ac\u20ac\u20ac" * 2000,
    "int": [123456789] * 1000,
    "double": [12345.987654321] * 1000,
    "long": [123456789123456789123456789123456789] * 1000,
    "tuple": [(x*x, "tuple", (300, 400, (500, 600, (x*x, x*x, x*x, x*x)))) for x in range(200)],
    "list": [[x*x, "tuple", [300, 400, [500, 600, [x*x, x*x, x*x, x*x]]]] for x in range(200)],
    "set": set(x*x for x in range(1000)),
    "dict": {i*i: {1000+j: chr(j+65) for j in range(5)} for i in range(100)},
    "exception": [ZeroDivisionError("test exeception", x*x) for x in range(1000)],
    "class": [Person("harry", x*x) for x in range(1000)]
}

serializers = {}
try:
    import pickle
    serializers["pickle"] = (pickle.dumps, pickle.loads)
except ImportError:
    pass
try:
    import cPickle
    serializers["cpickle"] = (cPickle.dumps, cPickle.loads)
except ImportError:
    pass
import json
serializers["json"] = (lambda d: json.dumps(d).encode("utf-8"), lambda d: json.loads(d.decode("utf-8")))
import serpent
if sys.version_info < (3, 0):
    # don't use set literals otherwise ast crashes on python < 3.0
    def serpent_dumps(data):<commit_msg>2 more types added to performance tester<commit_after>"""
Prints a comparison between different serializers.
Compares results based on size of the output, and time taken to (de)serialize.
"""

from __future__ import print_function
from timeit import default_timer as perf_timer
import sys
import datetime

class Person(object):
    def __init__(self, name, age):
        self.name = name
        self.age = age


data = {

    "bytes": b"0123456789abcdefghijklmnopqrstuvwxyz" * 2000,
    "bytearray": bytearray(b"0123456789abcdefghijklmnopqrstuvwxyz") * 2000,
    "str": "\"0123456789\"\n'abcdefghijklmnopqrstuvwxyz'\t" * 2000,
    "unicode": u"abcdefghijklmnopqrstuvwxyz\u20ac\u20ac\u20ac\u20ac\u20ac" * 2000,
    "int": [123456789] * 1000,
    "double": [12345.987654321] * 1000,
    "long": [123456789123456789123456789123456789] * 1000,
    "tuple": [(x*x, "tuple", (300, 400, (500, 600, (x*x, x*x, x*x, x*x)))) for x in range(200)],
    "list": [[x*x, "tuple", [300, 400, [500, 600, [x*x, x*x, x*x, x*x]]]] for x in range(200)],
    "set": set(x*x for x in range(1000)),
    "dict": {i*i: {1000+j: chr(j+65) for j in range(5)} for i in range(100)},
    "exception": [ZeroDivisionError("test exeception", x*x) for x in range(1000)],
    "class": [Person("harry", x*x) for x in range(1000)],
    "datetime": [datetime.datetime.now() for x in range(1000)],
    "complex": [complex(x+x, x*x) for x in range(1000)]
}

serializers = {}
try:
    import pickle
    serializers["pickle"] = (pickle.dumps, pickle.loads)
except ImportError:
    pass
try:
    import cPickle
    serializers["cpickle"] = (cPickle.dumps, cPickle.loads)
except ImportError:
    pass
import json
serializers["json"] = (lambda d: json.dumps(d).encode("utf-8"), lambda d: json.loads(d.decode("utf-8")))
import serpent
if sys.version_info < (3, 0):
    # don't use set literals otherwise ast crashes on python < 3.0
    def serpent_dumps(data):
{'fraction_non_alphanumeric': 0.16020742358078602, 'fraction_numerical': 0.10343886462882096, 'mean_word_length': 4.311594202898551, 'pattern_counts': {'":': 28, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3774607', 'n_tokens_mistral': 1685, 'n_tokens_neox': 1355, 'n_words': 366}