-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsize-benchmark.sh
More file actions
executable file
·59 lines (44 loc) · 1.52 KB
/
size-benchmark.sh
File metadata and controls
executable file
·59 lines (44 loc) · 1.52 KB
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
#!/usr/bin/env bash
# set safe shell mode
set -euo pipefail
columns=("Mode" "Text" "Data" "Bss" "Total")
modes=("ReleaseSmall" "ReleaseFast" "ReleaseSafe" "Debug")
echo "# Size benchmark" >SIZE_BENCHMARK.md
echo "" >>SIZE_BENCHMARK.md
echo "This document contains the size in bytes of the firmware for each optimize mode." >>SIZE_BENCHMARK.md
echo "" >>SIZE_BENCHMARK.md
echo '`Failed` means that the firmware is too large to fit in the flash memory.' >>SIZE_BENCHMARK.md
echo "" >>SIZE_BENCHMARK.md
build() {
local optimize="$1"
local dir="$2"
rm -rf "${dir}/zig-out"
(cd "${dir}" && zig build -Doptimize="$optimize" || true)
local size=$(size "${dir}/zig-out/firmware/ch32v003_blink.elf" | tail -n1 | awk '{print $1 " | " $2 " | " $3 " | " ($1 + $2 + $3)}' || echo "- | - | - | Failed")
echo "$size"
}
for dir in */; do
if [ ! -f "${dir}build.zig" ]; then
continue
fi
dir=$(sed 's/\/$//' <<<"$dir")
if [ "$dir" == "template" ]; then
continue
fi
echo "## ${dir}" >>SIZE_BENCHMARK.md
echo "" >>SIZE_BENCHMARK.md
for column in "${columns[@]}"; do
printf "| %s " "$column" >>SIZE_BENCHMARK.md
done
printf "|\n" >>SIZE_BENCHMARK.md
for column in "${columns[@]}"; do
printf "|--------" >>SIZE_BENCHMARK.md
done
printf "|\n" >>SIZE_BENCHMARK.md
for mode in "${modes[@]}"; do
size=$(build "$mode" "$dir")
echo "| $mode | $size | " >>SIZE_BENCHMARK.md
done
printf "\n\n" >>SIZE_BENCHMARK.md
done
echo 'This document was generated by `size-benchmark.sh` script.' >>SIZE_BENCHMARK.md