From 5943dab6907b4b49c48c2962c610bbcace3d324f Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Mon, 1 Jul 2024 13:47:57 +0200 Subject: [PATCH 1/4] wip --- tests/test_markdown.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 5e393d2..310da89 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -1,11 +1,14 @@ """Test markdown module.""" from datetime import datetime +import os from typing import Any import markdown import pytest +import blag +from blag.blag import build from blag.markdown import convert_markdown, markdown_factory @@ -111,3 +114,28 @@ this --- is -- a test ... assert "mdash" not in html assert "ndash" not in html assert "hellip" not in html + + +def test_performance(args) -> None: + # create 1000 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(1000): + with open(f"content/{i}.md", "w") as f: + f.write(markdown) + + from time import time + + t = time() + build(args) + print(time() - t) + + import cProfile + + t = time() + cProfile.run("build(args)") + #build(args) + print(time() - t) + + + 1 / 0 From c4f3c09730be2442c62a15bbe007b38a39c80dd2 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Mon, 8 Jul 2024 15:35:58 +0200 Subject: [PATCH 2/4] WIP --- Makefile | 4 ++++ tests/test_markdown.py | 28 ---------------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 5b8208e..2765cb4 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,10 @@ serve-docs: $(VENV) manpage: $(VENV) help2man $(BIN)/blag --no-info -n "blog-aware, static site generator" -o debian/blag.1 +.PHONY: benchmark +benchmark: $(VENV) + $(BIN)/pytest --no-cov -rP tests/benchmark.py + .PHONY: clean clean: rm -rf build dist *.egg-info diff --git a/tests/test_markdown.py b/tests/test_markdown.py index 310da89..5e393d2 100644 --- a/tests/test_markdown.py +++ b/tests/test_markdown.py @@ -1,14 +1,11 @@ """Test markdown module.""" from datetime import datetime -import os from typing import Any import markdown import pytest -import blag -from blag.blag import build from blag.markdown import convert_markdown, markdown_factory @@ -114,28 +111,3 @@ this --- is -- a test ... assert "mdash" not in html assert "ndash" not in html assert "hellip" not in html - - -def test_performance(args) -> None: - # create 1000 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(1000): - with open(f"content/{i}.md", "w") as f: - f.write(markdown) - - from time import time - - t = time() - build(args) - print(time() - t) - - import cProfile - - t = time() - cProfile.run("build(args)") - #build(args) - print(time() - t) - - - 1 / 0 From a3da95ea19387b77f0fe9462b11984fd8c7443eb Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Tue, 29 Oct 2024 12:13:05 +0100 Subject: [PATCH 3/4] added benchmark --- tests/benchmark.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/benchmark.py diff --git a/tests/benchmark.py b/tests/benchmark.py new file mode 100644 index 0000000..63a5aa2 --- /dev/null +++ b/tests/benchmark.py @@ -0,0 +1,30 @@ +import os + +import blag +from blag.blag import build + + +def test_performance(args) -> None: + # create 1000 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): + with open(f"content/{i}.md", "w") as f: + f.write(markdown) + f.write(str(i)) + + from time import time + + t = time() + build(args) + print(time() - t) + + import cProfile + + t = time() + #cProfile.run("build(args)") + build(args) + print(time() - t) + + + 1 / 0 From c94f9793b07fac5f88add6c4226ad1fa1b80b642 Mon Sep 17 00:00:00 2001 From: Bastian Venthur Date: Wed, 22 Jan 2025 14:46:14 +0100 Subject: [PATCH 4/4] 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