Created
May 18, 2018 10:20
-
-
Save georgf/7bdf97d7a1ce9f6442bc75b8cd1f0c2b to your computer and use it in GitHub Desktop.
quick test of msgpack vs. json encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import datetime | |
import json | |
import umsgpack | |
def time(what, fn): | |
start = datetime.datetime.now() | |
fn() | |
end = datetime.datetime.now() | |
print what + " took " + str(end - start) | |
paths = sys.argv[1:] | |
data = [] | |
print "... loading from disk" | |
for path in paths: | |
with open(path) as f: | |
data.append(json.load(f)) | |
print "... timing json encoding of " + str(len(data)) + " files" | |
def json_encoding(): | |
for d in data: | |
json.dumps(d) | |
time("json encoding", json_encoding) | |
end = datetime.datetime.now() | |
print "... timing msgpack encoding of " + str(len(data)) + " files" | |
def msgpack_encoding(): | |
for d in data: | |
umsgpack.packb(d) | |
time("msgpack encoding", msgpack_encoding) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At least the Python implementations encoding speed doesn't seem promising: