-
-
Save ringsaturn/5e8dab269d3c3d561d9b985ddc433d14 to your computer and use it in GitHub Desktop.
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 pickle | |
import time | |
import numpy as np | |
import orjson | |
import pandas._libs.json as pdujson | |
import nujson | |
n = 20000 | |
val = pickle.load(open('sample.pkl', 'rb')) | |
# Test orjson | |
def default(obj): | |
if isinstance(obj, np.ndarray): | |
return obj.tolist() | |
if isinstance(obj, np.float64): | |
return float(obj) | |
if isinstance(obj, np.str_): | |
return str(obj) | |
start = time.process_time() | |
for i in range(n): | |
orjson.dumps(val, default=default) | |
elapsed = (time.process_time() - start) | |
print("orjson time used:", elapsed) | |
# Test Pandas ujson | |
start = time.process_time() | |
for i in range(n): | |
pdujson.dumps(val) | |
elapsed = (time.process_time() - start) | |
print("pandas time used:", elapsed) | |
# Test nujson | |
start = time.process_time() | |
for i in range(n): | |
nujson.dumps(val) | |
elapsed = (time.process_time() - start) | |
print("nujson time used:", elapsed) | |
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
orjson time used: 18.883733 | |
pandas time used: 10.571927000000002 | |
nujson time used: 7.919490000000003 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment