mirror of
https://github.com/venthur/blag.git
synced 2025-11-25 20:52:43 +00:00
improved performance test
This commit is contained in:
2
Makefile
2
Makefile
@@ -67,7 +67,7 @@ manpage: $(VENV)
|
|||||||
|
|
||||||
.PHONY: benchmark
|
.PHONY: benchmark
|
||||||
benchmark: $(VENV)
|
benchmark: $(VENV)
|
||||||
$(BIN)/pytest --no-cov -rP tests/benchmark.py
|
$(BIN)/pytest --no-cov -s -rP tests/benchmark.py
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ from blag.blag import build
|
|||||||
|
|
||||||
|
|
||||||
def test_performance(args) -> None:
|
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:
|
with open(os.path.join(blag.__path__[0], "content", "testpage.md")) as fh:
|
||||||
markdown = fh.read()
|
markdown = fh.read()
|
||||||
for i in range(10000):
|
for i in range(FILES):
|
||||||
with open(f"content/{i}.md", "w") as f:
|
with open(f"content/{i}.md", "w") as f:
|
||||||
f.write(markdown)
|
f.write(markdown)
|
||||||
f.write(str(i))
|
f.write(str(i))
|
||||||
@@ -17,14 +19,13 @@ def test_performance(args) -> None:
|
|||||||
|
|
||||||
t = time()
|
t = time()
|
||||||
build(args)
|
build(args)
|
||||||
print(time() - t)
|
t_first = time() - t
|
||||||
|
print(t_first)
|
||||||
import cProfile
|
|
||||||
|
|
||||||
t = time()
|
t = time()
|
||||||
#cProfile.run("build(args)")
|
|
||||||
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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user