add bench target and scripts to run simple benchmark

This commit is contained in:
Noah Hellman 2023-01-31 22:51:16 +01:00
parent 87d4f7c270
commit 78987f7ba3
3 changed files with 28 additions and 0 deletions

View file

@ -13,6 +13,7 @@ documentation = "https://docs.rs/jotdown"
exclude = [
".gitmodules",
"Makefile",
"benches",
"modules",
"tests",
]

View file

@ -18,6 +18,13 @@ suite_bench:
(cd tests/bench && make)
cargo test --features suite_bench
.PHONY: bench
bench:
git submodule update --init modules/djot.js
for f in $$(find modules/djot.js/bench -name '*.dj' | xargs basename -a); do \
ln -fs ../modules/djot.js/bench/$$f benches/$$f; \
done
clean:
cargo clean
git submodule deinit -f --all
@ -25,3 +32,4 @@ clean:
(cd tests/suite && make clean)
rm -f tests/bench/*.dj
(cd tests/bench && make clean)
rm -f benches/*.dj

19
benches/bench.sh Executable file
View file

@ -0,0 +1,19 @@
#!/bin/sh
cmd=$*
test_html=$(echo "abc" | $cmd | tr -d ' \n')
[ "$test_html" != "<p>abc</p>" ] && echo "failed simple gen: '$test_html'" && exit 1
for f in *.dj; do
tmp=$(mktemp)
for i in $(seq 500); do
cat "$f" >> $tmp
done
t=$(cat "$tmp" \
| (LANG=C time -p $cmd > /dev/null) 2>&1 \
| grep real \
| awk '{print $2}')
printf "$t\t$f\n"
rm -f "$tmp"
done | sort -rn