build_a_blog: bench

This commit is contained in:
Collin Lefeber 2024-06-19 14:53:44 -04:00
parent 6cb7aa53df
commit e8276cb4e9
2 changed files with 81 additions and 0 deletions

22
bench.sh Executable file
View file

@ -0,0 +1,22 @@
#!/usr/bin/env bash
amt=$1
if [[ -z "$amt" ]]; then
echo "ERROR: pass number of test posts for bench" 1>&2
exit 1
fi
echo "INFO: removing old __bench files" 1>&2
rm -f ./posts/*__bench*
for i in $(seq 1 "$amt"); do
cp ./posts/build_a_blog.md ./posts/build_a_blog_${i}__bench.md
done
echo "INFO: number of *.md files $(find ./posts/ -iname '*.md' | wc -l)" 1>&2
echo "INFO: number of *.html files $(find ./posts/ -iname '*.html' | wc -l)" 1>&2
echo "INFO: running" 1>&2
time -p python main.py 2>/dev/null
echo "INFO: number of *.html files $(find ./posts/ -iname '*.html' | wc -l)" 1>&2
echo "INFO: cleanup __bench files" 1>&2
rm -f ./posts/*__bench*

View file

@ -652,6 +652,7 @@ It's not great software.
* Using adhoc dicts for generic structures
* Relies on system python version and packages.
* Does not offer anything a tool like [hugo][hugo] does not already offer.
* Probably slow in extreme cases.
But, it's ~150 lines of python with 1 external dependency.
@ -733,6 +734,64 @@ html should get generated, but not in the index or xml
0
```
### 2024-06-19, is it slow?
Quick benchmark script `bench.sh`
```shell
#!/usr/bin/env bash
amt=$1
if [[ -z "$amt" ]]; then
echo "ERROR: pass number of test posts for bench" 1>&2
exit 1
fi
echo "INFO: removing old __bench files" 1>&2
rm -f ./posts/*__bench*
for i in $(seq 1 "$amt"); do
cp ./posts/build_a_blog.md ./posts/build_a_blog_${i}__bench.md
done
echo "INFO: number of *.md files $(find ./posts/ -iname '*.md' | wc -l)" 1>&2
echo "INFO: number of *.html files $(find ./posts/ -iname '*.html' | wc -l)" 1>&2
echo "INFO: running" 1>&2
time -p python main.py 2>/dev/null
echo "INFO: number of *.html files $(find ./posts/ -iname '*.html' | wc -l)" 1>&2
echo "INFO: cleanup __bench files" 1>&2
rm -f ./posts/*__bench*
```
```shell
./bench.sh 100
INFO: removing old __bench files
INFO: number of *.md files 102
INFO: number of *.html files 2
INFO: running
real 0.94
user 0.92
sys 0.02
INFO: number of *.html files 102
INFO: cleanup __bench files
./bench.sh 1000
INFO: removing old __bench files
INFO: number of *.md files 1002
INFO: number of *.html files 2
INFO: running
real 8.45
user 8.31
sys 0.12
INFO: number of *.html files 1002
INFO: cleanup __bench files
```
So approx 0.8s per 100 posts which starts to get a bit painful in the thousands.
Will be a fun future idea to try to solve.
[1]: https://crystal-lang.org/
[2]: https://github.com/crystal-lang/crystal/releases/tag/0.31.0
[3]: https://pkgs.alpinelinux.org/package/edge/main/x86_64/py3-markdown