From e8276cb4e9e0168e0339bbc74b8caaf7ddcf2c0d Mon Sep 17 00:00:00 2001 From: Collin Lefeber Date: Wed, 19 Jun 2024 14:53:44 -0400 Subject: [PATCH] build_a_blog: bench --- bench.sh | 22 ++++++++++++++++ posts/build_a_blog.md | 59 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100755 bench.sh diff --git a/bench.sh b/bench.sh new file mode 100755 index 0000000..e6ba179 --- /dev/null +++ b/bench.sh @@ -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* diff --git a/posts/build_a_blog.md b/posts/build_a_blog.md index a6d0216..5091768 100644 --- a/posts/build_a_blog.md +++ b/posts/build_a_blog.md @@ -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