2626 import ujson
2727 import simplejson
2828 import yajl
29+ import orjson
2930
3031benchmark_results = []
3132
@@ -55,7 +56,7 @@ def results_record_result(callback, is_encode, count):
5556
5657
5758def 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
204215def 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
213225def 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
222235def 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 ()
0 commit comments