From c94f9793b07fac5f88add6c4226ad1fa1b80b642 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Wed, 22 Jan 2025 14:46:14 +0100 Subject: [PATCH] improved performance test --- Makefile | 2 +- tests/benchmark.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 2765cb4..cbaadaa 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ manpage: $(VENV) .PHONY: benchmark benchmark: $(VENV) - $(BIN)/pytest --no-cov -rP tests/benchmark.py + $(BIN)/pytest --no-cov -s -rP tests/benchmark.py .PHONY: clean clean: diff --git a/tests/benchmark.py b/tests/benchmark.py index 63a5aa2..3766f21 100644 --- a/tests/benchmark.py +++ b/tests/benchmark.py @@ -5,10 +5,12 @@ from blag.blag import build def test_performance(args) -> None: - # create 1000 random markdown files in the content directory + FILES = 1000 + print(f"Generating {FILES} files") + # create random markdown files in the content directory with open(os.path.join(blag.__path__[0], "content", "testpage.md")) as fh: markdown = fh.read() - for i in range(10000): + for i in range(FILES): with open(f"content/{i}.md", "w") as f: f.write(markdown) f.write(str(i)) @@ -17,14 +19,13 @@ def test_performance(args) -> None: t = time() build(args) - print(time() - t) - - import cProfile + t_first = time() - t + print(t_first) t = time() - #cProfile.run("build(args)") build(args) - print(time() - t) + t_second = time() - t + print(t_second) + print(f"First run: {t_first:.2f}s, second run: {t_second:.2f}s") + print(f"Speedup: {t_first/t_second:.2f}") - - 1 / 0