-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.sh
executable file
·70 lines (60 loc) · 2.26 KB
/
benchmark.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
THISDIR="$(cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")" && pwd)"
DEPS=(hyperfine curl)
for dep in "${DEPS[@]}"; do
command -v "$dep" >/dev/null 2>&1 || {
echo "'$dep' required but not found" >&2
exit 1
}
done
pushd "${THISDIR}" >/dev/null || exit 1
{
# Download other template engines -----------------------------------------
[[ -e mo ]] || {
echo "Downloading mo ..."
curl -SL https://git.io/get-mo -o mo &&
chmod +x mo
} || exit 1
[[ -e bash-tpl ]] || {
echo "Downloading bash-tpl ..."
curl -SL https://github.com/TekWizely/bash-tpl/releases/download/v0.7.0/bash-tpl -o bash-tpl &&
chmod +x bash-tpl
} || exit 1
[[ -e renderest ]] || {
echo "Downloading renderest ..."
curl -SL https://raw.githubusercontent.com/relaxdiego/renderest/master/render -o renderest &&
chmod +x renderest
}
[[ -e shtpl ]] || {
echo "Downloading shtpl ..."
curl -SL https://raw.githubusercontent.com/mlorenzo-stratio/shtpl/main/shtpl -o shtpl &&
chmod +x shtpl
}
ln -sf ../bpt.sh bpt.sh
# Prepare test files ------------------------------------------------------
echo "aaa" >|"0vars.tpl"
{ echo -n 'echo ' && for _ in {1..1000}; do echo -n "\${var}"; done; } >|"1000vars.sh"
for _ in {1..1000}; do echo -n "\$var"; done >|"1000vars.shtpl"
for _ in {1..1000}; do echo -n "{{var}}"; done >|"1000vars.tpl"
for _ in {1..1000}; do echo -n "<%\$var%>"; done >|"1000vars.bash-tpl"
# Benchmark ---------------------------------------------------------------
hyperfine \
--runs 10 --warmup 2 \
--export-markdown result-0vars.md \
"bash -c 'echo \"aaa\"'" \
"./shtpl 0vars.tpl" \
"./renderest 0vars.tpl" \
". <(./bash-tpl 0vars.tpl)" \
"./mo 0vars.tpl" \
"./bpt.sh ge 0vars.tpl"
hyperfine \
--runs 10 --warmup 2 \
--export-markdown result-1000vars.md \
"var=a bash 1000vars.sh" \
"var=a ./shtpl < 1000vars.shtpl" \
"var=a ./renderest 1000vars.tpl" \
"var=a . <(./bash-tpl 1000vars.bash-tpl)" \
"var=a ./mo 1000vars.tpl" \
"var=a ./bpt.sh ge 1000vars.tpl"
}
popd >/dev/null || exit 1