1
0
mirror of https://github.com/venthur/blag.git synced 2025-11-26 05:02:58 +00:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Bastian Venthur
60bd86ec22 finalized benchmark 2025-01-22 15:17:28 +01:00
Bastian Venthur
69b729a471 Merge branch 'performance' into rebuild_needed_only 2025-01-22 14:46:42 +01:00
Bastian Venthur
f09e841200 Merge branch 'master' into rebuild_needed_only 2025-01-22 14:46:29 +01:00
Bastian Venthur
71c866c9b3 Merge branch 'master' into rebuild_needed_only 2023-11-12 17:16:46 +01:00
Bastian Venthur
c87a300c71 Merge branch 'master' into rebuild_needed_only 2022-08-07 21:50:15 +02:00
Bastian Venthur
a939e6503c rebuild only files that need re-building
we compare the mtimes of src and dst
2022-08-06 21:56:41 +02:00
3 changed files with 26 additions and 8 deletions

View File

@@ -67,7 +67,7 @@ manpage: $(VENV)
.PHONY: benchmark .PHONY: benchmark
benchmark: $(VENV) benchmark: $(VENV)
$(BIN)/pytest --no-cov -s -rP tests/benchmark.py $(BIN)/pytest --no-cov -capture=no -rA tests/benchmark.py
.PHONY: clean .PHONY: clean
clean: clean:

View File

@@ -323,6 +323,18 @@ def process_markdown(
for src, dst in convertibles: for src, dst in convertibles:
logger.debug(f"Processing {src}") logger.debug(f"Processing {src}")
# see first if the dst actually needs re-building. for that we compare
# the mtimes and assume mtime_dst > mtime_src means that it needs not
# to be rebuilt
if os.path.exists(f"{output_dir}/{dst}"):
mtime_src = os.stat(f"{input_dir}/{src}").st_mtime
mtime_dst = os.stat(f"{output_dir}/{dst}").st_mtime
if mtime_dst >= mtime_src:
logger.debug(
"Skipping, as target exists and is newer than source."
)
continue
with open(f"{input_dir}/{src}") as fh: with open(f"{input_dir}/{src}") as fh:
body = fh.read() body = fh.read()

View File

@@ -1,12 +1,21 @@
"""Benchmark the performance of the blag build command."""
import logging
import os import os
from argparse import Namespace
from pytest import LogCaptureFixture
import blag import blag
from blag.blag import build from blag.blag import build
def test_performance(args) -> None: def test_performance(args: Namespace, caplog: LogCaptureFixture) -> None:
FILES = 1000 """Test performance of the build command."""
print(f"Generating {FILES} files") caplog.set_level(logging.ERROR)
FILES = 10000
print(f"Generating {FILES} markdown files")
# create random markdown files in the content directory # create random markdown files in the content directory
with open(os.path.join(blag.__path__[0], "content", "testpage.md")) as fh: with open(os.path.join(blag.__path__[0], "content", "testpage.md")) as fh:
markdown = fh.read() markdown = fh.read()
@@ -20,12 +29,9 @@ def test_performance(args) -> None:
t = time() t = time()
build(args) build(args)
t_first = time() - t t_first = time() - t
print(t_first)
t = time() t = time()
build(args) build(args)
t_second = 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"First run: {t_first:.2f}s, second run: {t_second:.2f}s")
print(f"Speedup: {t_first/t_second:.2f}") print(f"Speedup: {t_first/t_second:.2f}")