Skip to content

Commit

Permalink
Add micro-benchmark which measures the overhead of using default
Browse files Browse the repository at this point in the history
function for orjson.dumps.
  • Loading branch information
Kami committed May 22, 2021
1 parent 33a3af5 commit fb2dce4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ micro-benchmarks: requirements .micro-benchmarks
. $(VIRTUALENV_DIR)/bin/activate; pytest --benchmark-histogram=benchmark_histograms/benchmark --benchmark-only --benchmark-name=short --benchmark-columns=min,max,mean,stddev,median,ops,rounds --benchmark-group-by=group,param:fixture_file -s -v st2common/benchmarks/micro/test_fast_deepcopy.py -k "test_fast_deepcopy_with_json_fixture_file"
. $(VIRTUALENV_DIR)/bin/activate; pytest --benchmark-histogram=benchmark_histograms/benchmark --benchmark-only --benchmark-name=short --benchmark-columns=min,max,mean,stddev,median,ops,rounds --benchmark-group-by=group,param:fixture_file,param:indent_sort_keys_tuple -s -v st2common/benchmarks/micro/test_json_serialization_and_deserialization.py -k "test_json_dumps"
. $(VIRTUALENV_DIR)/bin/activate; pytest --benchmark-histogram=benchmark_histograms/benchmark --benchmark-only --benchmark-name=short --benchmark-columns=min,max,mean,stddev,median,ops,rounds --benchmark-group-by=group,param:fixture_file -s -v st2common/benchmarks/micro/test_json_serialization_and_deserialization.py -k "test_json_loads"
. $(VIRTUALENV_DIR)/bin/activate; pytest --benchmark-histogram=benchmark_histograms/benchmark --benchmark-only --benchmark-name=short --benchmark-columns=min,max,mean,stddev,median,ops,rounds --benchmark-group-by=group,param:fixture_file -s -v st2common/benchmarks/micro/test_json_serialization_and_deserialization.py -k "test_orjson_dumps"
. $(VIRTUALENV_DIR)/bin/activate; pytest --benchmark-histogram=benchmark_histograms/benchmark --benchmark-only --benchmark-name=short --benchmark-columns=min,max,mean,stddev,median,ops,rounds --benchmark-group-by=group,param:fixture_file -s -v st2common/benchmarks/micro/test_publisher_compression.py -k "test_pickled_object_compression"
. $(VIRTUALENV_DIR)/bin/activate; pytest --benchmark-histogram=benchmark_histograms/benchmark --benchmark-only --benchmark-name=short --benchmark-columns=min,max,mean,stddev,median,ops,rounds --benchmark-group-by=group,param:fixture_file -s -v st2common/benchmarks/micro/test_publisher_compression.py -k "test_pickled_object_compression_publish"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,47 @@ def run_benchmark():

result = benchmark(run_benchmark)
assert result == content_loaded


def default_handle_sets(obj):
if isinstance(obj, set):
return list(obj)
raise TypeError


@pytest.mark.parametrize(
"fixture_file",
[
"rows.json",
"json_4mb.json",
],
ids=[
"rows.json",
"json_4mb.json",
],
)
@pytest.mark.parametrize(
"options",
[
{},
{"default": default_handle_sets},
],
ids=[
"none",
"custom_default_function",
],
)
def test_orjson_dumps(benchmark, fixture_file, options):
with open(os.path.join(FIXTURES_DIR, fixture_file), "r") as fp:
content = fp.read()

content_loaded = orjson.loads(content)

if options:
content_loaded["fooo_set"] = set([1, 2, 3, 3, 4, 5])

def run_benchmark():
return orjson.dumps(content_loaded, **options)

result = benchmark(run_benchmark)
assert len(result) >= 100

0 comments on commit fb2dce4

Please sign in to comment.