Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit 1626d3d

Browse files
committed
Merge branch 'master' of github.com:mre/hyperjson
2 parents 6ef6a45 + fd79077 commit 1626d3d

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ nightly: ## Set rust compiler to nightly version
2121

2222
.PHONY: install
2323
install: nightly dev-packages ## Install hyperjson module into current virtualenv
24-
pipenv run maturin develop
24+
pipenv run maturin develop --release
2525

2626
.PHONY: publish
2727
publish: ## Publish crate on Pypi
@@ -48,7 +48,7 @@ bench: ## Run benchmarks
4848
pipenv run pytest benchmarks
4949

5050
.PHONY: bench-compare
51-
bench-compare: ## Run benchmarks and compare results with other JSON encoders
51+
bench-compare: nightly dev-packages install ## Run benchmarks and compare results with other JSON encoders
5252
pipenv run pytest benchmarks --compare
5353

5454
.PHONY: plot

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pytest-benchmark = "*"
1010
simplejson = "*"
1111
ujson = "*"
1212
yajl = "*"
13+
orjson = "*"
1314
python-rapidjson = "*"
1415
wheel = "*"
1516
pylint = "*"

benchmarks/benchmark_ujson.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import ujson
2727
import simplejson
2828
import yajl
29+
import orjson
2930

3031
benchmark_results = []
3132

@@ -55,7 +56,7 @@ def results_record_result(callback, is_encode, count):
5556

5657

5758
def results_output_table():
58-
LIBRARIES = ("hyperjson", "ujson", "yajl", "simplejson", "json")
59+
LIBRARIES = ("hyperjson", "ujson", "yajl", "simplejson", "json", "orjson")
5960
ENDC = '\033[0m'
6061
GREEN = '\033[92m'
6162

@@ -143,6 +144,9 @@ def dumps_with_yajl():
143144
yajl.dumps(test_object)
144145

145146

147+
def dumps_with_orjson():
148+
orjson.dumps(test_object)
149+
146150
# =============================================================================
147151
# JSON encoding with sort_keys=True.
148152
# =============================================================================
@@ -166,6 +170,9 @@ def dumps_sorted_with_ujson():
166170
ujson.dumps(test_object, ensure_ascii=False, sort_keys=True)
167171

168172

173+
def dumps_sorted_with_orjson():
174+
orjson.dumps(test_object, sort_keys=True)
175+
169176
# =============================================================================
170177
# JSON decoding.
171178
# =============================================================================
@@ -189,6 +196,9 @@ def loads_with_yajl():
189196
yajl.loads(decode_data)
190197

191198

199+
def load_with_orjson():
200+
orjson.loads(test_object)
201+
192202
# =============================================================================
193203
# Benchmarks.
194204
# =============================================================================
@@ -199,6 +209,7 @@ def run_decode(count):
199209
results_record_result(loads_with_simplejson, False, count)
200210
results_record_result(loads_with_yajl, False, count)
201211
results_record_result(loads_with_json, False, count)
212+
results_record_result(loads_with_orjson, False, count)
202213

203214

204215
def run_encode(count):
@@ -208,6 +219,7 @@ def run_encode(count):
208219
results_record_result(dumps_with_simplejson, True, count)
209220
results_record_result(dumps_with_yajl, True, count)
210221
results_record_result(dumps_with_json, True, count)
222+
results_record_result(dumps_with_orjson, True, count)
211223

212224

213225
def run_encode_sort_keys(count):
@@ -217,6 +229,7 @@ def run_encode_sort_keys(count):
217229
results_record_result(dumps_sorted_with_simplejson, True, count)
218230
results_record_result(dumps_sorted_with_yajl, True, count)
219231
results_record_result(dumps_sorted_with_json, True, count)
232+
results_record_result(dumps_sorted_with_orjson, True, count)
220233

221234

222235
def benchmark_array_doubles():
@@ -370,7 +383,6 @@ def benchmark_complex_object():
370383
benchmark_array_true_values()
371384
benchmark_array_of_dict_string_int_pairs()
372385
benchmark_dict_of_arrays_of_dict_string_int_pairs()
373-
# Disabled for now because of https://github.com/PyO3/pyo3/issues/177
374-
# benchmark_complex_object()
386+
benchmark_complex_object()
375387
if not skip_lib_comparisons:
376388
results_output_table()

conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ def pytest_addoption(parser):
5959
rapidjson.dumps,
6060
rapidjson.loads))
6161

62+
try:
63+
import orjson
64+
except ImportError:
65+
pass
66+
else:
67+
contenders.append(Contender('orjson',
68+
orjson.dumps,
69+
orjson.loads))
70+
6271

6372
def pytest_generate_tests(metafunc):
6473
if 'contender' in metafunc.fixturenames:

0 commit comments

Comments
 (0)