Created
September 28, 2020 16:18
-
-
Save dp-quant/3caa11cd7ab409f99eb043ac0b69db1e to your computer and use it in GitHub Desktop.
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 time | |
import json | |
import orjson | |
import rapidjson | |
m = { | |
"timestamp": 1556283673.1523004, | |
"task_uuid": "0ed1a1c3-050c-4fb9-9426-a7e72d0acfc7", | |
"task_level": [1, 2, 1], | |
"action_status": "started", | |
"action_type": "main", | |
"key": "value", | |
"another_key": 123, | |
"and_another": ["a", "b"], | |
} | |
def benchmark(name, dumps): | |
start = time.time() | |
for i in range(1000000): | |
dumps(m) | |
print(name, time.time() - start) | |
benchmark("Python", json.dumps) | |
# orjson only outputs bytes, but often we need unicode: | |
benchmark("orjson", lambda s: str(orjson.dumps(s), "utf-8")) | |
benchmark("rapidjson", rapidjson.dumps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment