Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created July 25, 2015 06:50
Show Gist options
  • Save hirokiky/232786642af6547eeb00 to your computer and use it in GitHub Desktop.
Save hirokiky/232786642af6547eeb00 to your computer and use it in GitHub Desktop.
msgpack vs json
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)
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