blob: b14bf57847c941537b2f420912ca2618d2631055 (
plain) (
blame)
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
|
#!/bin/bash
# byte-string scan, concat and slice, timed on a run-only image so the
# resident compiler is not in the process. the slope between 1 repetition
# and N drops startup. prints: backend ms/rep checksum
cd "$(dirname "$0")/../.."
CC=${CC:-$(sh src/tools/findcc.sh)} || exit 1
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
$CC -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
"$T/genmap" --preset run -o "$T/run" >/dev/null || exit 1
cp src/tools/zc0.c src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h src/core/genome.h "$T/run/"
$CC -O1 -w "$T/run/zc0.c" -o "$T/zc0" || exit 1
cat "$T/run/rt.zc" src/core/core.zc src/runtime/run.zc tests/programs/bench_strings.zc | "$T/zc0" > "$T/run/genome.bin" || exit 1
$CC -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
$CC -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
vms=("$T/zy" "$T/zym"); names=("interp" "micro")
if command -v llvm-config >/dev/null; then
$CC -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
&& { vms+=("$T/zyl"); names+=("llvm"); }
fi
if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyj" \
&& { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64"); }
fi
once(){ local s e; s=$(date +%s.%N); printf '%s' "$2" | $1 >/tmp/bench_strings.out; e=$(date +%s.%N); python3 -c "print($e - $s)"; }
printf "%-10s %12s %s\n" backend "ms/rep" checksum
for i in "${!vms[@]}"; do
one=$(once "${vms[$i]}" 1)
many=$(once "${vms[$i]}" 40)
ms=$(python3 -c "print(round(($many - $one) / 39 * 1000, 3))")
sum=$(tr -d '\n' < /tmp/bench_strings.out)
printf "%-10s %12s %s\n" "${names[$i]}" "$ms" "$sum"
done
|