Created
July 25, 2015 06:50
-
-
Save hirokiky/232786642af6547eeb00 to your computer and use it in GitHub Desktop.
msgpack vs json
This file contains 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 msgpack | |
data = {} # Input large Python dict | |
import time | |
import json | |
print("Dumping") | |
print("########### msgpack ##############") | |
print("started") | |
t = time.time() | |
for _ in range(10000): | |
msgpack.packb(data) | |
print(time.time() - t) | |
print("########### json ##############") | |
print("started") | |
t = time.time() | |
for _ in range(10000): | |
json.dumps(data) | |
print(time.time() - t) | |
print("Loading") | |
print("########### msgpack ##############") | |
packed = msgpack.packb(data) | |
print("started") | |
t = time.time() | |
for _ in range(10000): | |
msgpack.unpackb(packed) | |
print(time.time() - t) | |
print("########### json ##############") | |
dumped = json.dumps(data) | |
print("started") | |
t = time.time() | |
for _ in range(10000): | |
json.loads(dumped) | |
print(time.time() - t) |
This file contains 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
Dumping | |
########### msgpack ############## | |
started | |
1.8405179977416992 | |
########### json ############## | |
started | |
2.8371567726135254 | |
Loading | |
########### msgpack ############## | |
started | |
0.7938659191131592 | |
########### json ############## | |
started | |
12.04452896118164 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment