diff --git a/Makefile b/Makefile index b0f48ab..647bf1e 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ bench: ## Run benchmarks pipenv run pytest benchmarks .PHONY: bench-compare -bench-compare: ## Run benchmarks and compare results with other JSON encoders +bench-compare: nightly dev-packages install ## Run benchmarks and compare results with other JSON encoders pipenv run pytest benchmarks --compare .PHONY: plot diff --git a/Pipfile b/Pipfile index bc3ef68..a65807f 100644 --- a/Pipfile +++ b/Pipfile @@ -10,6 +10,7 @@ pytest-benchmark = "*" simplejson = "*" ujson = "*" yajl = "*" +orjson = "*" python-rapidjson = "*" wheel = "*" pylint = "*" diff --git a/benchmarks/benchmark_ujson.py b/benchmarks/benchmark_ujson.py index e795023..1e83d02 100644 --- a/benchmarks/benchmark_ujson.py +++ b/benchmarks/benchmark_ujson.py @@ -26,6 +26,7 @@ import ujson import simplejson import yajl + import orjson benchmark_results = [] @@ -55,7 +56,7 @@ def results_record_result(callback, is_encode, count): def results_output_table(): - LIBRARIES = ("hyperjson", "ujson", "yajl", "simplejson", "json") + LIBRARIES = ("hyperjson", "ujson", "yajl", "simplejson", "json", "orjson") ENDC = '\033[0m' GREEN = '\033[92m' @@ -143,6 +144,9 @@ def dumps_with_yajl(): yajl.dumps(test_object) +def dumps_with_orjson(): + orjson.dumps(test_object) + # ============================================================================= # JSON encoding with sort_keys=True. # ============================================================================= @@ -166,6 +170,9 @@ def dumps_sorted_with_ujson(): ujson.dumps(test_object, ensure_ascii=False, sort_keys=True) +def dumps_sorted_with_orjson(): + orjson.dumps(test_object, sort_keys=True) + # ============================================================================= # JSON decoding. # ============================================================================= @@ -189,6 +196,9 @@ def loads_with_yajl(): yajl.loads(decode_data) +def load_with_orjson(): + orjson.loads(test_object) + # ============================================================================= # Benchmarks. # ============================================================================= @@ -199,6 +209,7 @@ def run_decode(count): results_record_result(loads_with_simplejson, False, count) results_record_result(loads_with_yajl, False, count) results_record_result(loads_with_json, False, count) + results_record_result(loads_with_orjson, False, count) def run_encode(count): @@ -208,6 +219,7 @@ def run_encode(count): results_record_result(dumps_with_simplejson, True, count) results_record_result(dumps_with_yajl, True, count) results_record_result(dumps_with_json, True, count) + results_record_result(dumps_with_orjson, True, count) def run_encode_sort_keys(count): @@ -217,6 +229,7 @@ def run_encode_sort_keys(count): results_record_result(dumps_sorted_with_simplejson, True, count) results_record_result(dumps_sorted_with_yajl, True, count) results_record_result(dumps_sorted_with_json, True, count) + results_record_result(dumps_sorted_with_orjson, True, count) def benchmark_array_doubles(): @@ -370,7 +383,6 @@ def benchmark_complex_object(): benchmark_array_true_values() benchmark_array_of_dict_string_int_pairs() benchmark_dict_of_arrays_of_dict_string_int_pairs() - # Disabled for now because of https://github.com/PyO3/pyo3/issues/177 - # benchmark_complex_object() + benchmark_complex_object() if not skip_lib_comparisons: results_output_table() diff --git a/conftest.py b/conftest.py index 559c404..92da5f8 100644 --- a/conftest.py +++ b/conftest.py @@ -59,6 +59,15 @@ def pytest_addoption(parser): rapidjson.dumps, rapidjson.loads)) +try: + import orjson +except ImportError: + pass +else: + contenders.append(Contender('orjson', + orjson.dumps, + orjson.loads)) + def pytest_generate_tests(metafunc): if 'contender' in metafunc.fixturenames: