diff --git a/Makefile b/Makefile index bbca5f1..ca201f8 100644 --- a/Makefile +++ b/Makefile @@ -40,10 +40,13 @@ format: ## Fix python formatting issues where possible @ruff format . && ruff . --fix --show-fixes test: ## Run unit test suite - @py.test + @py.test --benchmark-skip + +bench: ## Run benchmark test suite + @py.test --benchmark-only coverage: ## Run coverage and create html report - coverage run -m pytest + coverage run -m pytest --benchmark-skip coverage html -d coverage_html build: clean ## builds source and wheel package diff --git a/pyproject.toml b/pyproject.toml index 68440d0..b28d4fe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,6 +31,7 @@ requires-python = ">=3.8" [project.optional-dependencies] dev = [ "pytest ~=7.4.4", + "pytest-benchmark", "flit ~= 3.9.0", "ruff ~= 0.1.13", "coverage ~= 7.4.0", diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py new file mode 100644 index 0000000..120ef2f --- /dev/null +++ b/tests/test_benchmark.py @@ -0,0 +1,88 @@ +import rispy + +EXAMPLE_RECORD = """ +42. +TY - JOUR +ID - 12345 +T1 - The title of the reference +A1 - Marxus, Karlus +A1 - Lindgren, Astrid +A2 - Glattauer, Daniel +Y1 - 2006// +N2 - BACKGROUND: Lorem dammed ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. RESULTS: Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. CONCLUSIONS: Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. +KW - Pippi Langstrumpf +KW - Nordwind +KW - Piraten +KW - Seeräuber +KW - Kinderbuch +KW - Astrid Lindgren +JF - Lorem ipsum dolor sit amet +JA - lorem ipsum dolor sit amet +VL - 6 +IS - 3 +SP - e0815341 +CY - Germany +PB - Dark Factory +SN - 1732-4208 +M1 - 1228150341 +L2 - http://example2.com +UR - http://example.com/1 +UR - http://example.com/2 +UR - http://example.com/3 +DO - 10.1371/journal.pone.0081534 +ER - + +""" # noqa + + +EXAMPLE_RECORD_MULTILINE = """ +42. +TY - JOUR +ID - 12345 +T1 - The title of the reference +A1 - Marxus, Karlus +A1 - Lindgren, Astrid +A2 - Glattauer, Daniel +Y1 - 2006// +N2 - BACKGROUND: Lorem dammed ipsum dolor sit amet, +consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. + - Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus + - mus. RESULTS: Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. + Nulla consequat massa quis enim. CONCLUSIONS: Donec pede justo, fringilla vel, aliquet +nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam +dictum felis eu pede mollis pretium. +KW - Pippi Langstrumpf +KW - Nordwind +KW - Piraten +KW - Seeräuber +KW - Kinderbuch +KW - Astrid Lindgren +JF - Lorem ipsum dolor sit amet +JA - lorem ipsum dolor sit amet +VL - 6 +IS - 3 +SP - e0815341 +CY - Germany +PB - Dark Factory +SN - 1732-4208 +M1 - 1228150341 +L2 - http://example2.com +UR - http://example.com/1 +UR - http://example.com/2 +UR - http://example.com/3 +DO - 10.1371/journal.pone.0081534 +ER - + +""" + + +def test_benchmark_rispy_large(benchmark): + benchmark_dataset = EXAMPLE_RECORD * 10000 + + benchmark(rispy.loads, benchmark_dataset) + + +def test_benchmark_rispy_large_multiline(benchmark): + benchmark_dataset = EXAMPLE_RECORD_MULTILINE * 10000 + + benchmark(rispy.loads, benchmark_dataset)