From 668ae9a8b7a7b98e829029b3ba45741800b12ec5 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Tue, 27 Aug 2024 13:37:33 +0200 Subject: [PATCH 1/7] Add benchmark for rispy --- benchmark/rispy_benchmark.py | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 benchmark/rispy_benchmark.py diff --git a/benchmark/rispy_benchmark.py b/benchmark/rispy_benchmark.py new file mode 100644 index 0000000..9db3d72 --- /dev/null +++ b/benchmark/rispy_benchmark.py @@ -0,0 +1,48 @@ +import timeit + +import rispy # noqa + +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 + + +def make_dataset(n=10000): + return EXAMPLE_RECORD * n + + +if __name__ == "__main__": + ristext = make_dataset() + + time_result = timeit.timeit("rispy.loads(ristext)", globals=globals(), number=100) + print(f"Time: {time_result:.4f} s") From 7083ba52ddaffaa4d2d340ba1e38fcc2d42010cd Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Tue, 27 Aug 2024 14:48:42 +0200 Subject: [PATCH 2/7] Happy lint --- benchmark/rispy_benchmark.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/rispy_benchmark.py b/benchmark/rispy_benchmark.py index 9db3d72..f3edb1c 100644 --- a/benchmark/rispy_benchmark.py +++ b/benchmark/rispy_benchmark.py @@ -45,4 +45,4 @@ def make_dataset(n=10000): ristext = make_dataset() time_result = timeit.timeit("rispy.loads(ristext)", globals=globals(), number=100) - print(f"Time: {time_result:.4f} s") + print(f"Time: {time_result:.4f} s") # noqa From fc2bd7b641e62122f71155088624c14bf445d474 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Thu, 29 Aug 2024 09:52:39 +0200 Subject: [PATCH 3/7] Replace benchmark script with pytest-benchmark with more benchmarks --- Makefile | 5 +- benchmark/rispy_benchmark.py | 48 ------------------ pyproject.toml | 1 + tests/test_benchmark.py | 96 ++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 49 deletions(-) delete mode 100644 benchmark/rispy_benchmark.py create mode 100644 tests/test_benchmark.py diff --git a/Makefile b/Makefile index bbca5f1..87396af 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,10 @@ 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 diff --git a/benchmark/rispy_benchmark.py b/benchmark/rispy_benchmark.py deleted file mode 100644 index f3edb1c..0000000 --- a/benchmark/rispy_benchmark.py +++ /dev/null @@ -1,48 +0,0 @@ -import timeit - -import rispy # noqa - -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 - - -def make_dataset(n=10000): - return EXAMPLE_RECORD * n - - -if __name__ == "__main__": - ristext = make_dataset() - - time_result = timeit.timeit("rispy.loads(ristext)", globals=globals(), number=100) - print(f"Time: {time_result:.4f} s") # noqa 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..c1ce236 --- /dev/null +++ b/tests/test_benchmark.py @@ -0,0 +1,96 @@ +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_single(benchmark): + benchmark(rispy.loads, EXAMPLE_RECORD) + + +def test_benchmark_rispy_single_multiline(benchmark): + benchmark(rispy.loads, EXAMPLE_RECORD_MULTILINE) + + +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) From f9046679f49ec354771c7a56a645bc199f2ab3cc Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Thu, 29 Aug 2024 10:03:53 +0200 Subject: [PATCH 4/7] Diasable single tests --- tests/test_benchmark.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index c1ce236..c0c1ecb 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -1,3 +1,5 @@ +import pytest + import rispy EXAMPLE_RECORD = """ @@ -76,10 +78,12 @@ """ +@pytest.mark.skip("Skip benchmark single tests") def test_benchmark_rispy_single(benchmark): benchmark(rispy.loads, EXAMPLE_RECORD) +@pytest.mark.skip("Skip benchmark single tests") def test_benchmark_rispy_single_multiline(benchmark): benchmark(rispy.loads, EXAMPLE_RECORD_MULTILINE) From d100cab755484d3f8c26d6b2779e3c8344c8cad4 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Tue, 20 May 2025 19:27:11 +0200 Subject: [PATCH 5/7] Skip benchmark for coverage --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 87396af..ca201f8 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ 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 From 4ae89a3810f59d0b557af85c2d12c71fe68807a1 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Tue, 20 May 2025 19:27:28 +0200 Subject: [PATCH 6/7] Remove single benchmarks --- tests/test_benchmark.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index c0c1ecb..4bed5fc 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -78,16 +78,6 @@ """ -@pytest.mark.skip("Skip benchmark single tests") -def test_benchmark_rispy_single(benchmark): - benchmark(rispy.loads, EXAMPLE_RECORD) - - -@pytest.mark.skip("Skip benchmark single tests") -def test_benchmark_rispy_single_multiline(benchmark): - benchmark(rispy.loads, EXAMPLE_RECORD_MULTILINE) - - def test_benchmark_rispy_large(benchmark): benchmark_dataset = EXAMPLE_RECORD * 10000 From 316e703e2199be34d2c51e1c25ef4d1a6fb2dd33 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Tue, 20 May 2025 19:28:35 +0200 Subject: [PATCH 7/7] Happy lint --- tests/test_benchmark.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 4bed5fc..120ef2f 100644 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -1,5 +1,3 @@ -import pytest - import rispy EXAMPLE_RECORD = """