Skip to content

Commit

Permalink
Merge pull request #16 from gerrymanoim/benchmark-list-access
Browse files Browse the repository at this point in the history
BENCH: Add random Array indexing benchmark
  • Loading branch information
gerrymanoim authored Jul 18, 2020
2 parents cf09d1e + 5373441 commit 8037f5f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
PYTHONWARNINGS: ignore:DEPRECATION::pip._internal.cli.base_command
run: |
python -m pip install --upgrade pip
pip install numpy libpy
pip install numpy libpy pybind11
- name: Install
if: steps.check.outputs.triggered == 'true'
run: |
Expand Down
40 changes: 39 additions & 1 deletion libpy_simdjson/tests/test_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ujson import loads as ujson_loads
from rapidjson import loads as rapidjson_loads
from simdjson import loads as pysimdjson_loads
from simdjson import parse as pysimdjson_parse
from libpy_simdjson import loads as libpy_simdjson_loads

from libpy_simdjson import Array
Expand All @@ -29,7 +30,8 @@ def libpy_simdjson_as_py_obj(input):
@pytest.mark.parametrize(
["group", "func"],
[
("pysimdjson", pysimdjson_loads),
("pysimdjson_as_py_obj", pysimdjson_loads),
("pysimdjson", pysimdjson_parse),
("orjson", orjson_loads),
("ujson", ujson_loads),
("rapidjson", rapidjson_loads),
Expand Down Expand Up @@ -91,3 +93,39 @@ def py_test_func(doc):
content = f.read()
doc = read_func(content)
benchmark(bench_func, doc)


@pytest.mark.parametrize(
["group", "read_func"],
[
("python_json", json_loads),
("libpy_simdjson", libpy_simdjson_loads),
],
)
def test_benchmark_list_access(group, read_func, benchmark):
benchmark.group = "Random list access"
benchmark.extra_info["group"] = group

random.seed(999)

def simd_test_func(doc):
selection = random.randrange(10_000)
doc[selection]

def py_test_func(doc):
selection = random.randrange(10_000)
doc[selection]

if group == "libpy_simdjson":
bench_func = simd_test_func
elif group == "python_json":
bench_func = py_test_func
else:
raise ValueError("unknown group for direct access test")

json_doc = JSON_FIXTURES_DIR / "numbers.json"
with json_doc.open('rb') as f:
content = f.read()
doc = read_func(content)
benchmark(bench_func, doc)

1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def extension(*args, **kwargs):
"orjson",
"python-rapidjson",
"pysimdjson",
"pybind11", # used by pysimdjson if wheels do not exist
"ujson",
],
},
Expand Down

0 comments on commit 8037f5f

Please sign in to comment.